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.

Batch and Composite Requests

Batch and composite APIs pose special challenges, because they handle multiple requests in a single call. In Swift, Mobile SDK extensions reduce the pain of building and configuring these complex requests.

Batch and Composite Request Classes

Swift
  • 1BatchRequest
  • 1BatchRequestBuilder
  • 1BatchResponse
  • 1CompositeRequest
  • 1CompositeRequestBuilder
  • 1CompositeResponse
Objective-C
  • 1SFSDKBatchRequest
  • 1SFSDKBatchRequestBuilder
  • 1SFSDKBatchResponse
  • 1SFSDKCompositeRequest
  • 1SFSDKCompositeRequestBuilder
  • 1SFSDKCompositeResponse

These classes make it easy to create batch and composite requests. To use them:

  1. Create a builder instance. For batch requests, you can optionally set haltOnError property to true:
    1let builder = BatchRequestBuilder()
    2// Optional; defaults to false
    3builder.setHaltOnError(true)
    For composite requests, you can optionally set the allOrNone rollback property to true.
    1let builder = CompositeRequestBuilder()
    2// Optional; defaults to false
    3builder.setAllOrNone(true)
  2. As you create REST requests, add them to the builder object.
    1builder.add(request as! BatchRequest)
    With composite requests, you also provide a reference ID as described in the REST API Developer Guide. You can add a base RestRequest object and specify the reference ID explicitly:
    1builder.add(request, referenceId)
    or add a CompositeSubRequest object, which is a RestRequest object that stores the reference ID internally:
    1builder.add(request as! CompositeSubRequest)
  3. When you’re ready, call the builder object’s build method—buildBatchRequest(_:) or buildCompositeRequest(_:). For example:
    1let request = builder.buildBatchRequest(SFRestDefaultAPIVersion)
    Each build method returns a specialized BatchRestRequest or CompositeRestRequest object. You can send these objects through the shared RestClient instance.

    To use an older API version as the default argument, pass a literal string in the format “v42.0”.

    Tip

  4. Responses to batch and composite requests arrive as instances of the response class (BatchResponse or CompositeResponse).