+ Start a Discussion

Retrieve vs Query

When using the Partner API, and you know the ID for a record that you want to retireve from an object, which method should be used (Retrieve or Query)?
I'm asking this question so that I used the most optimized (fastest) method in my Application.
Mike LeachMike Leach
From the 7.0 API Documentation:


Retrieves one or more objects based on the specified object IDs.

sObject[] result = sfdc.retrieve(string fieldList, string sObjectType, ID ids[]);

Use the retrieve call to retrieve individual records from an object. The client application passes the list of fields to retrieve, the object, and an array of object IDs to retrieve. The retrieve call does not return records that have been deleted.

In general, you use retrieve when you know in advance the IDs of the records to retrieve. Use query instead to obtain records when you do not know the IDs or when you want to specify other selection criteria.

Client applications can use retrieve to perform a client-side join. For example, a client application can run a query to obtain a set of Opportunity records, iterate through the returned Opportunity records, obtain the accountId for each Opportunity, and then call retrieve to obtain Account information for those accountIds.

Certain objects cannot be retrieved via the API. To retrieve an object via the retrieve call, its object must be configured as retrieveable (retrieveable is True). To determine whether an object can be retrieved, your client application can invoke the describeSObjects call on the object and inspect its retrievable property.

Your client application must be logged in with sufficient access rights to retrieve individual objects within the specified object and to retrieve the fields in the specified field list. For more information, see Factors that Affect Data Access.