Salesforce Object Ids and API Usage Reduction

This guide describes some common patterns for using and storing Salesforce Object IDs and strategies to reduce the number of API calls (because the two go hand-in-hand).

The guide builds on the topics discussed in Identifier Field Handling

Why are IDs needed?

Two primary reasons:

  • The object id is a unique identifier in Salesforce assigned to every object. To update an object you can pass the id of the object (or an external id dependent on setup).
  • To associate one object to another. 
    • For example, to associate a Price Book entry to a Price Book, to associate an Opportunity to an Account.

Why Do you need to reduce API Calls?

Your Salesforce account is provided a fixed number of API calls per day. Once you exceed the threshold, you cannot make any further API calls.

See API Call Usage for more details.

Using & Storing Salesforce Object IDs

When syncing data to Salesforce it is recommended you store the IDs of the Salesforce objects against the record (Customer, Product, Order, etc) in the source system i.e. Sage.

Salesforce object ids are generated by Salesforce whenever a new object is created. If you map an empty field to the ID field of the object, the Salesforce ID is written back to the IMan dataset.

Each time the object needs to be updated the Salesforce Id is already stored in the source system, no lookups required.

External IDs

External IDs short circuit the need to store Salesforce IDs, but they suffer from two issues, which can limit their use:

  • IMan does not have the capability to handle objects which have multiple fields marked as External. We understand this is a rare case, but in more complex scenarios where there are multiple systems passing data into and out of salesforce, another application may have already marked a field with an external id.
  • External Ids cannot be used when associating one record to another. For example a price book entry upload could not use a (new, custom) field on the price book itself which is marked an external field and use this in place of the object's actual id.

Use Lookups Judiciously

Salesforce Lookups give you the ability to query Salesforce anywhere within IMan where VBScript expression is supported. This provides you with the capability for obtaining the id of a record using a known value (item code, customer, id, order number) to a Salesforce Object Id.

This gives you vast flexibility, but you should be careful in their use (as their cost is not free):

  • Slow - Each time a lookup is performed, it could result in a request being made to Salesforce. When performing lookups over multiple 1000's of records this can be slow.
  • API Call Consumption - Each lookup consumes an API call.

The aim is to reduce the number of lookups.

If you need an object's id, for associating one object to another try to obtain the value once.

Example #1

The Sage 200 Item & Pricing Upload and Sage 300 Item & Pricing Upload To Salesforce jobs use a strategy where the IDs for each Salesforce Pricebook are obtained on the first record of the dataset, and then the ids are copied to each record using the PreviousRecord function. This approach is most useful when the value will be the same for all records being processed.

Dim PriceListName
Dim Result

If PreviousRecord("PriceBookId") = "" Then
  PriceListName = "Standard"
  Result = CustomLookup("SALESFORCE", "Id", "PriceBook2", "Name = '" & PriceListName & "'", "", False)
Else
  Result = PreviousRecord("PriceBookId")
End If

Result

Example #2

In a similar approach to above, you can use the RegisterValue and GetRegisteredValue functions.

This approach is useful when value being looked up is different across the records. It allows you to store the result of the lookup using the RegisterValue function, and each record can check if the record has been previously looked up using the GetRegisteredValue function.

Dim Result
Dim Key

Key = "SFPB-" & %PriceListName

Result = GetRegisteredValue(Key)
			
If Result = "" Then
  Result = CustomLookup("SALESFORCE", "Id", "PriceBook2", "Name = '" & %PriceListName & "'", "", False)
  RegisterValue Key, Result
End If

Result