function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
H_ManH_Man 

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.
 
Thanks!
 
Mike LeachMike Leach
From the 7.0 API Documentation:

retrieve
--------------------------------------------------------------------------------

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

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

Usage
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.