java.lang.Object
org.apache.camel.component.salesforce.api.dto.composite.SObjectBatch
All Implemented Interfaces:
Serializable

public final class SObjectBatch extends Object implements Serializable
Builder for Composite API batch request. Composite API is available from Salesforce API version 34.0 onwards its a way to combine multiple requests in a batch and submit them in one HTTP request. This object help to build the payload of the batch request. Most requests that are supported in the Composite batch API the helper builder methods are provided. For batch requests that do not have their corresponding helper builder method, use addGeneric(Method, String) or addGeneric(Method, String, Object) methods. To build the batch use:
 {
     @code
     SObjectBatch batch = new SObjectBatch("37.0");

     final Account account = new Account();
     account.setName("NewAccountName");
     account.setIndustry(Account_IndustryEnum.ENVIRONMENTAL);
     batch.addCreate(account);

     batch.addDelete("Account", "001D000000K0fXOIAZ");

     batch.addGet("Account", "0010Y00000Arwt6QAB", "Name", "BillingPostalCode");
 }

 
This will build a batch of three operations, one to create new Account, one to delete an Account, and one to get two fields from an Account.
See Also:
  • Constructor Details

    • SObjectBatch

      public SObjectBatch(String apiVersion)
      Create new batch request. You must specify the API version of the batch request. The API version cannot be newer than the version configured in the Salesforce Camel component. Some of the batched requests are available only from certain Salesforce API versions, when this is the case it is noted in the documentation of the builder method, if uncertain consult the Salesforce API documentation.
      Parameters:
      apiVersion - API version for the batch request
  • Method Details

    • addCreate

      public SObjectBatch addCreate(AbstractDescribedSObjectBase data)
      Add create SObject to the batch request.
      Parameters:
      data - object to create
      Returns:
      this batch builder
    • addDelete

      public SObjectBatch addDelete(String type, String id)
      Add delete SObject with identifier to the batch request.
      Parameters:
      type - type of SObject
      id - identifier of the object
      Returns:
      this batch builder
    • addGeneric

      public SObjectBatch addGeneric(SObjectBatch.Method method, String url)
      Generic way to add requests to batch. Given URL starts from the version, so in order to retrieve SObject specify just /sobjects/Account/identifier which results in /services/data/v37.0/sobjects/Account/identifier. Note the leading slash.
      Parameters:
      method - HTTP method
      url - URL starting from the version
      Returns:
      this batch builder
    • addGeneric

      public SObjectBatch addGeneric(SObjectBatch.Method method, String url, Object richInput)
      Generic way to add requests to batch with richInput payload. Given URL starts from the version, so in order to update SObject specify just /sobjects/Account/identifier which results in /services/data/v37.0/sobjects/Account/identifier. Note the leading slash.
      Parameters:
      method - HTTP method
      url - URL starting from the version
      richInput - body of the request, to be placed in richInput
      Returns:
      this batch builder
    • addGet

      public SObjectBatch addGet(String type, String id, String... fields)
      Add field retrieval of an SObject by identifier to the batch request.
      Parameters:
      type - type of SObject
      id - identifier of SObject
      fields - to return
      Returns:
      this batch builder
    • addGetByExternalId

      public SObjectBatch addGetByExternalId(String type, String fieldName, String fieldValue)
      Add field retrieval of an SObject by external identifier to the batch request.
      Parameters:
      type - type of SObject
      fieldName - external identifier field name
      fieldValue - external identifier field value
      Returns:
      this batch builder
    • addGetRelated

      public SObjectBatch addGetRelated(String type, String id, String relation, String... fields)
      Add retrieval of related SObject fields by identifier. For example Account has a relation to CreatedBy. To fetch fields from that related object (User SObject) use:
       
       batch.addGetRelated("Account", identifier, "CreatedBy", "Name", "Id")
       
       
      Parameters:
      type - type of SObject
      id - identifier of SObject
      relation - name of the related SObject field
      fields - to return
      Returns:
      this batch builder
    • addLimits

      public SObjectBatch addLimits()
      Add retrieval of limits to the batch.
      Returns:
      this batch builder
    • addQuery

      public SObjectBatch addQuery(String query)
      Add retrieval of SObject records by query to the batch.
      Parameters:
      query - SOQL query to execute
      Returns:
      this batch builder
    • addQueryAll

      public SObjectBatch addQueryAll(String query)
      Add retrieval of all SObject records by query to the batch.
      Parameters:
      query - SOQL query to execute
      Returns:
      this batch builder
    • addSearch

      public SObjectBatch addSearch(String searchString)
      Add retrieval of SObject records by search to the batch.
      Parameters:
      searchString - SOSL search to execute
      Returns:
      this batch builder
    • addUpdate

      public SObjectBatch addUpdate(String type, String id, AbstractSObjectBase data)
      Add update of SObject record to the batch. The given data parameter must contain only the fields that need updating and must not contain the Id field. So set any fields to null that you do not want changed along with Id field.
      Parameters:
      type - type of SObject
      id - identifier of SObject
      data - SObject with fields to change
      Returns:
      this batch builder
    • addUpdateByExternalId

      public SObjectBatch addUpdateByExternalId(String type, String fieldName, String fieldValue, AbstractSObjectBase data)
      Add update of SObject record by external identifier to the batch. The given data parameter must contain only the fields that need updating and must not contain the Id field. So set any fields to null that you do not want changed along with Id field.
      Parameters:
      type - type of SObject
      fieldName - name of the field holding the external identifier
      fieldValue - external identifier value
      data - SObject with fields to change
      Returns:
      this batch builder
    • addUpsertByExternalId

      public SObjectBatch addUpsertByExternalId(String type, String fieldName, String fieldValue, AbstractSObjectBase data)
      Add insert or update of SObject record by external identifier to the batch. The given data parameter must contain only the fields that need updating and must not contain the Id field. So set any fields to null that you do not want changed along with Id field.
      Parameters:
      type - type of SObject
      fieldName - name of the field holding the external identifier
      fieldValue - external identifier value
      data - SObject with fields to change
      Returns:
      this batch builder
    • getBatchRequests

      public List<org.apache.camel.component.salesforce.api.dto.composite.BatchRequest> getBatchRequests()
      Fetches batch requests contained in this batch.
      Returns:
      all requests
    • getVersion

      public Version getVersion()
      Version of Salesforce API for this batch request.
      Returns:
      the version
    • objectTypes

      public Class[] objectTypes()
      Returns all object types nested within this batch, needed for serialization.
      Returns:
      all object types in this batch