I found the following code example online:

    long waitTimeMilliSecs = ONE_SECOND;

    // After the create() call completes, we must poll the results of the checkStatus()
    // call until it indicates that the create operation has completed.
    do {
        waitTimeMilliSecs *= 2;
        asyncResults = metadataConnection.checkStatus(new String[]{asyncResults[0].getId()});
    } while (!asyncResults[0].isDone());

1, 3, 7 and 15 Seconds is a long time to wait for a response... I'd like to write my application to respond faster than that especially in the event of a 3.1 second response! The question is, what is behind the isDone() method of AsyncResults? Does it just check a local boolean that some other thread will eventually set to true, or does it fire query out to salesforce to get a status report?

The documentation doesn't seem to say anything one way or another, but the long wait times in the example make it look like they think it is expensive.

1 Answer 1


The isDone() method is not expensive. It's just a helper method to access the status of the underlying request. The only expensive call is the checkStatus() call which requires a round trip to the Salesforce servers. However, it's just asking for the status, so barring network congestion this is a pretty fast call.

As to why the 1, 3, 7, 15 seconds. Deployments can vary a lot in terms of how long to complete. If you're working in sandbox most deployments happen fairly quickly (usually between 1-10s). However, most deployments to production requiring running all test methods in the org which can be VERY expensive. For one client I've worked with who had a lot of APEX code and test methods running all the tests could take up to 45 minutes!! The tutorial is gradually increasing the check period, so that for long deployments you're making efficient use of your API calls. That said, there wait time increase is a little silly since doubling can quickly result in very long wait times. Best to start small and then quickly increase to a maximum of say one minute before polling again.

  • I see, however querying for metadata shouldn't run the tests and therefore should be much faster right?
    – Gus
    Feb 27, 2013 at 4:02
  • That's correct. The more components your querying the slower the call, but it'll always be far faster than deployments. Feb 27, 2013 at 14:01

You must log in to answer this question.

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