When we use ant deployment here is the folder hierarchy which we use-
ANT Sample Folder
>>mypkg Folder
>>retrieveUnpackaged Folder
>> removecodepkg Folder [Create this new folder to delete the files]
>>build.properties files
>>build.xml
To delete a resource you need to add a destructiveChanges.xml file in removecodepkg folder. The destructiveChanges.xml file is same as package.xml. format of this file is as below-
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>LoginController</members>
<members>LoginControllerTest</members>
<name>ApexClass</name>
</types>
<version>19.0</version>
</Package>
You also need to have a blank package.xml file in the same removecodepkg folder. Format of the file will be-
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<version>19.0</version>
</Package>
Now you have two xml files in removecodepkg folder –
1-destructiveChanges.xml
2-package.xml
ant is having build.xml file which have all commands can be executed. There will be a command to delete the code-
<target name="undeployCode">
<sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="removecodepkg"/>
</target>
Now mention the name of the resource in destructiveChanges.xml file & delete the file from destination org. in our example I am deleting a class LoginController & it’s test class.
You just need to execute below command on ant
>>ant undeployCode
Perfect! Thanks :)
ReplyDelete