The Salesforce SOAP API’s getUpdated() is designed to return all objects of a given type, inserted or updated within a given timeframe. IDs for updated records will then be returned and the Salesforce docs then recommends the use of retrieve() calls for every returned ID to get details about the changed records.
An alternative approach would be to use the query()/queryMore() calls. Using these calls I will be able to use significantly fewer API calls, and – I’d say – generally a simpler setup in my client application.
Why would I use the getUpdated()/retrieve() calls instead of query()/queryMore with a SOQL in style with:
SELECT Id, Subject, ... FROM Task WHERE LastModifiedDate >= 2013-01-27T00:00:00Z AND LastModifiedDate < 2013-01-28T00:00:00Z
I cannot find any performance arguments in the documentation?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Specifically for the getUpdated() case, you are correct that you can do a query/queryMore alternative by building the correct where clause. However the where clause differs by object type. You should use the SystemModstamp field where available, if it doesn’t have that, then use LastModifiedDate and if it doesn’t have that, use CreatedDate. This is basically what getUpdated() is doing under the covers.
If you’re writing something generic, then the additional describe calls needed to determine the correct where clause, can tip the balance back to getUpdated()/retrieve().
But, it worth understanding that there is no SOQL equivalent for getDeleted(), many types of rows can be hard deleted and so a queryAll with isDeleted=true will not spot these deletes, but getDeleted() will (which keeps a separate delete log). Its important to use getDeleted() to replicate the deletes to your external system.
While superfell and Mohith’s answers are correct, they miss the nuanced detail of why you’d use getUpdated() versus query().
If you’re building a synchronization between Salesforce and some other database and recording a ‘high water mark’ of the most recent date of a record changed, you could potentially ‘miss’ a record change if a transaction was under way when you ran your query() since the SystemModstamp of the records in the other transaction may have an earlier date than the ones visible by your query().
This answer covers it with more detail (superfell’s answer): At what point in the transaction lifecycle is SystemModstamp set?
getUpdated()/retrieve() automatically gives you the updated record and hence no need for the extra query .Also if the platform is giving any standard methods its general practice to follow those as those reduce code.
In addition to everything which has been already said: query()/queryMore() enables to search objects within any timeframe, whereas using getUpdated() you can only go 1 month back.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0