Deploying with the Force.com Migration Tool (ANT)

August 6th, 2008

The Force.com Migration Tool is a Java/Ant-based command-line utility for moving metadata between a local directory and a Force.com organization. It runs essentially the same as the Eclipse version but provides a little more granular control.

Setting up Eclipse with Ant.

Initially was getting the following error during the build process “Problem: failed to create task or type”. I had to add the ant-saleforce.jar to the Ant runtime classpath (Window > Preferences > Ant > Runtime).

These are instructions for setting up a new project for “Sandbox1″

  1. Created a new project in Eclipse called “Deploy” for all of the deployment operations.
  2. Set the salesforce.com username, password and serverurl in the build.properties file.
  3. Created a folder under src for the sandbox (eg Sandbox1, Sun), so the resulting folder was Deploy/src/Sandbox1.
  4. In the Sandbox1 folder put package.xml which specifies the components that will be downloaded from the target instance. You can download all or specify the file names for each type. A sample package.xml is below. Objects will be downloaded to src/Sandbox1/src directory.
1
2
3
4
5
6
7
8
    <types>
        <members>CreateCampaignStatusesTriggerTest</members>
        <name>ApexClass</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexTrigger</name>
    </types>

Retrieve Command

You can download any files/folders from the target instance and delete them as needed.

Deploy

When you deploy to the target it using the deployRoot of ‘Sandbox1/src’, Ant looks at the package.xml file in the ‘Sandbox1/src’ folder to determine which objects to deploy. It appears that the package must contain a reference to all of the files that are in the directories or else it will fail.

If you try to deploy to one of the sandboxes that doesn’t have enough code coverage, then the deploy operation will fail.

To deploy them all to prodcution, just change the build.properties setting and run deployRunAllTests or deployRunNamedTests for the desired sandbox files.

Sample package.xml file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>*</members>
        <name>ApexClass</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexComponent</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexPage</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexTrigger</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomApplication</name>
    </types>
    <types>
        <members>*</members>
        <members>Account</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomTab</name>
    </types>
    <types>
        <members>*</members>
        <name>HomePageComponent</name>
    </types>
    <types>
        <members>*</members>
        <name>HomePageLayout</name>
    </types>
    <types>
        <members>*</members>
        <name>Letterhead</name>
    </types>
    <types>
        <members>*</members>
        <name>Profile</name>
    </types>
    <types>
        <members>*</members>
        <name>Scontrol</name>
    </types>
    <types>
        <members>*</members>
        <name>StaticResource</name>
    </types>
    <version>13.0</version>
</package>

Categories: Java, Salesforce

Leave a comment

Comments Feed2 Comments

  1. Paul

    Can you use this tool to migrate reports and dashboards? If so, got any ideas how?

    Thanks,

    Paul

  2. Brian Kessler

    I’m sure I’m missing something… possibly because my knowledge and experience with Ant has been very limited.

    I created a new Java Project and copied the Sample directory from salesforce_ant_20.0.zip into it. I modified build.properties and ran build.xml in eclipse to test this. That all worked fine.

    So, I created Sandbox1 in the src directory and copied package.xml from my SFDC project into it. I then copied build.properties and build.xml from sample into the src directory. Now, when I went to run build.xml, it complained about the deployRoot mypkg not existing. I changed the deployRoot to Sandbox1 and tried to test again. Below is the result:

    Buildfile: D:\education\sfdc\Deploy\src\build.xml
    test:
    [sf:deploy] Request for a deploy submitted successfully.
    [sf:deploy] Request Id for the current deploy task: 04sA0000002GwsGIAS
    [sf:deploy] Waiting for server to finish processing the request…
    [sf:deploy] Request Status: Completed

    BUILD FAILED
    D:\education\sfdc\Deploy\src\build.xml:14: FAILURES:
    Error: package.xml(Account):An object ‘Account’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(AccountContactRole):An object ‘AccountContactRole’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Activity):An object ‘Activity’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Asset):An object ‘Asset’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Campaign):An object ‘Campaign’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(CampaignMember):An object ‘CampaignMember’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Case):An object ‘Case’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(CaseContactRole):An object ‘CaseContactRole’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Contact):An object ‘Contact’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(ContentVersion):An object ‘ContentVersion’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Contract):An object ‘Contract’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(ContractContactRole):An object ‘ContractContactRole’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Event):An object ‘Event’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Idea):An object ‘Idea’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Lead):An object ‘Lead’ of type CustomObject was named in package.xml, but was not found in zipped directory
    Error: package.xml(Opportunity):An object ‘Opportunity’ of type CustomObject was named in package.xml, but was not found in zipped directory

    Any idea what I did wrong or how to fix it?

Leave a comment

Feed

http://blog.jeffdouglas.com / Deploying with the Force.com Migration Tool (ANT)

WordPress Appliance - Powered by TurnKey Linux