Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Collection Upsert

Updates or inserts a collection of objects from external data.

Mobile SDK provides a custom response object for parsing Collection request results. See Collection Response.

Parameters

Salesforce inserts or updates a record depending on whether an external ID currently exists in the external ID field. To force Salesforce to create a new record, set the name of the external ID field to “Id” and the external ID value to null.

For collections, you can disallow partial upserts by specifying an all-or-none parameter. When you set this parameter to true, Mobile SDK rolls back the entire request if any record upsert fails.

  • API version (string, optional)
  • "All or none" preference (Boolean)
  • Object type (string)
  • External ID field name (string)
  • Records (array)

iOS

Swift
1let request = RestClient.shared.requestForCollectionUpsert(allOrNone: allOrNone, 
2    withObjectType: objectType, externalIdField: externalIdFieldName!,
3    records: records!, apiVersion: nil)
Objective-C
1- (SFRestRequest*) 
2requestForCollectionUpsert:(BOOL)allOrNone 
3                objectType:(NSString*)objectType 
4           externalIdField:(NSString*)externalIdField 
5                   records:(NSArray<NSDictionary*>*)records 
6                apiVersion:(nullable NSString *)apiVersion;

Android

Kotlin
1val request = 
2    RestRequest.getRequestForCollectionUpsert(ApiVersionStrings.getVersionNumber(this), 
3        allOrNone, objectType, externalIdFieldName, records)
Java
1public static RestRequest getRequestForCollectionUpsert(
2    String apiVersion, boolean allOrNone, String objectType, String externalIdField, 
3    JSONArray records) 
4    throws JSONException

React Native

1collectionUpsert = <T>(
2  allOrNone: boolean,
3  objectType: string,
4  externalIdField: string,
5  records: Array<Record<string, unknown>>,
6  successCB: ExecSuccessCallback<T>,
7  errorCB: ExecErrorCallback,
8): void