0

I set up and ran destructiveChanges.xml through the ANT tool to delete custom fields from the Activity object in the sandbox.

I am getting an error -

Error: Not in package.xml

build file:

<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">

    <!--<property file="build.properties"/>-->
    <property environment="env"/>

     <property name="my.pkgName" value="Activity Custom Fields" />

    <!-- Setting default value for username, password and session id properties to empty string 
         so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
         will be treated literally.
    -->
    <condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
    <condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
    <condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

    <taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
        <classpath>
            <pathelement location="ant-salesforce.jar"/>            
        </classpath>
    </taskdef>

     <target name="retrievePkg">
      <mkdir dir="${my.pkgName}"/>

      <sf:retrieve username="my username" password="pw and security token" sessionId="${sf.sessionId}" serverurl="https://test.salesforce.com" maxPoll="200" retrieveTarget="${my.pkgName}"  packageNames="${my.pkgName}" />
    </target>
    <!-- Shows deploying code & running tests for code in directory -->
    <target name="deployScript">

      <sf:deploy 
            checkOnly="false"
            username="my username" 
            password="pw and security token" 
            serverurl="https://test.salesforce.com" 
            maxPoll="10000" 
            pollWaitMillis="1000" 
            deployRoot="C:\\Salesforce\\Activity Custom Fields"
            testLevel="NoTestRun"
            ignoreWarnings="true">
      </sf:deploy>
    </target>   
  </project>

destructiveChanges.xml:

    <?xml version="1.0" encoding="UTF-8"?>

-<Package xmlns="http://soap.sforce.com/2006/04/metadata">

<fullName>Activity Custom Fields</fullName>

<description>Custom fields on the activity object for deletion.</description>


-<types>

<members>Activity.Alert_Users__c</members>

<members>Activity.Attendance__c</members>

<members>Activity.CCR_Data__c</members>

<members>Activity.CCR_Functionality__c</members>

<members>Activity.CCR_Messaging__c</members>

<members>Activity.CCR_Resource_Allocation__c</members>

<members>Activity.CCR_Training__c</members>

<members>Activity.Campaign_Design_Profile_Name__c</members>

<members>Activity.Campaign_Event__c</members>

<members>Activity.Client_Request_Goal__c</members>

<members>Activity.Company_List__c</members>

<members>Activity.Company_Suppression_List__c</members>

<members>Activity.Contact_Information__c</members>

<members>Activity.Contact_List__c</members>

<members>Activity.Contact_Suppression_List__c</members>

<members>Activity.DC_Agent__c</members>

<members>Activity.D_B_PO_Number__c</members>

<members>Activity.Data_Team_Comments__c</members>

<members>Activity.Date_Delivered__c</members>

<members>Activity.Date_Sent_to_Partner__c</members>

<members>Activity.Deadline_Not_Met_Reason__c</members>

<members>Activity.Delivery_Channel__c</members>

<members>Activity.ETA_Back_to_Sales__c</members>

<members>Activity.Employee_Count__c</members>

<members>Activity.Industry__c</members>

<members>Activity.Install_Base__c</members>

<members>Activity.Key_Resources__c</members>

<members>Activity.Location_Type__c</members>

<members>Activity.Master_CDP_Number__c</members>

<members>Activity.New_ETA__c</members>

<members>Activity.No_Owner_Match__c</members>

<members>Activity.Notes__c</members>

<members>Activity.PO_Number__c</members>

<members>Activity.Partner_Contacts__c</members>

<members>Activity.Partner_Orgs__c</members>

<members>Activity.Partner__c</members>

<members>Activity.Product_Name__c</members>

<members>Activity.Production_Contacts__c</members>

<members>Activity.Production_Org__c</members>

<members>Activity.Reachforce_PO_number__c</members>

<members>Activity.Reason_Due_Date_Not_Met__c</members>

<members>Activity.Region__c</members>

<members>Activity.Reopen_Reason__c</members>

<members>Activity.Request_Status__c</members>

<members>Activity.Request_Type__c</members>

<members>Activity.Revised_Due_Date__c</members>

<members>Activity.Sales_Comments__c</members>

<members>Activity.Sales_Revenue__c</members>

<members>Activity.Social_123_PO_Number__c</members>

<members>Activity.Source_ID__c</members>

<members>Activity.Status_Notes__c</members>

<members>Activity.Target_Department__c</members>

<members>Activity.Target_Level__c</members>

<members>Activity.Type_of_Visit__c</members>

<members>Activity.Visit_Date_s__c</members>

<members>Activity.Zip_Code__c</members>

<members>Activity.Zip_Radius__c</members>

<name>CustomField</name>

</types>

<version>43.0</version>

</Package>

package.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>43.0</version>
</Package>
6
  • Would you please edit to include your destructiveChanges.xml and package.xml used for this job?
    – David Reed
    Commented Jul 24, 2019 at 19:17
  • 1
    The package.xml in your destructive run should be empty.... (other than the version tag) Commented Jul 24, 2019 at 19:32
  • May try sfdx force:source:delete? Commented Jul 24, 2019 at 21:01
  • @BrianMiller I'm not familiar with that function or how/where to use it.
    – Laura Babb
    Commented Jul 24, 2019 at 23:40
  • @SebastianKessel I have made the package.xml empty other than the version tag, but now the build fails on Error: Not in package.xml -- any ideas here? Is it my build file? Would it be helpful if I post my build script?
    – Laura Babb
    Commented Jul 24, 2019 at 23:41

2 Answers 2

5

The package.xml file is not constructed correctly for a destructive deployment:

To deploy the destructive changes, you must also have a package.xml file that lists no components to deploy, includes the API version, and is in the same directory as destructiveChanges.xml

You should remove all of the component declarations from your package.xml and retry.

Rolling up from comments... When performing a destructive deployment, the only items in your ZIP package or payload should be the package.xml and destructiveChanges.xml files. If you're getting errors that say

Error: Not in package.xml

that suggests that your payload is not being built correctly and actually contains metadata components that are not in your package.xml (which is empty). The Metadata API complains because it's getting the component metadata, but not a declaration of what to do with it (the package).

That is not what you want here, and you also don't want to do a deployment with destructiveChangesPost.xml, which does a regular deployment first and then performs a deletion.

Without seeing the details of your build scripts, we can't tell you what is getting built and why. If you just need to perform a destructive deployment, you can do so by creating a ZIP archive yourself with the two XML files you need and using Workbench to perform the operation directly, rather than going through Ant.

Ant Script Details

Based on the Ant script you've shared, it appears that your Ant is configured only to perform a deployment of a specific folder, currently set to deployRoot="C:\\Salesforce\\Activity Custom Fields". You'd want to set that parameter to point at a directory that does not contain any metadata files. It should contain only the package.xml and the destructiveChanges.xml files. If the directory contains metadata files, such as custom field information, you will receive an error stating that there are components not in package.xml.

4
  • I added the build script. I am not familiar with workbench and am a sf admin, not a developer (obviously). I learned this last year from a developer who had me run this as destructiveChangesPost. Since you don't recommend that, I am trying to learn the right way. I also read the ANT material in the developer site since you posted the link and I am not understanding what I'm doing wrong. I appreciate your help.
    – Laura Babb
    Commented Jul 25, 2019 at 0:20
  • @LauraBabb I will expand on this answer tomorrow to try to address those issues.
    – David Reed
    Commented Jul 25, 2019 at 1:55
  • Have you had an opportunity to look at this?
    – Laura Babb
    Commented Jul 29, 2019 at 14:42
  • 1
    @LauraBabb I added a few more details/suggestions at the end
    – David Reed
    Commented Jul 29, 2019 at 14:56
0

The most likely reason for that "Not in package.xml" error is that you have the metadata folders in the same folder as the package.xml and destructiveChanges.xml.

The two xml files need to be in a folder by themselves.

Thanks @David Reed. It was in your answer, but I wanted to emphasize it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .