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 RestRequestobject 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).

See Also 

We've Moved

Welcome to the new home of the Mobile SDK Developer Guide! For now, the Japanese guide can be found in PDF form.