Blog

Apache ant timeouts

0

Some time ago I had trouble deploying code using the Force.com IDE. I found it quite unreliable and it seemed to take forever to deploy even the most simple code, so I adopted the ‘old fashioned’ approach and started using the salesforce ant tool. Of course, the Force.com IDE provides a greater level of functionality than the ant tool – but for the straightforward deployment of code I have found it works a treat.

The one problem that I did find using the ant tool, was that I would randomly get timeout errors. I’d try deploying the exact same code again until eventually I got the ‘BUILD SUCCESSFUL’ I wanted. At first I presumed that it was a connectivity issue, but after a while I realised there was little pattern. So I decided to do some investigation and eventually found the solution.

When you download the ant tool from salesforce (http://www.salesforce.com/downloads/ApexTools/salesforce_ant.zip – requires login) and extract the contents, the sample folder contains two files:

build.properties
build.xml

At the top of build.properties you will see:

# Specify the login credentials for the desired Salesforce organization
sf.username = insert
sf.password = insert
#sf.pkgName = insert
#sf.zipFile = insert

And the build.xml file contains a line as follows, which access variables from the build.properties file above:

sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployroot="unpackaged"

To solve the timeout issue, we need to add a couple of additional values to both of these files. First, edit build.properties to make it look like this:

sf.username = insert
sf.password = insert
sf.maxPoll = 500
sf.maxWaitMillis = 5000

And then modify your build.xml to utilise these new variables as follows:

sf:deploy username="${sf.username}" password="${sf.password}" maxPoll="${sf.maxPoll}" pollWaitMillis="${sf.maxWaitMillis}" serverurl="${sf.serverurl}" deployRoot="unpackaged"

With any luck you should now find that your code will deploy every time with no timeout errors.