Class SObjectComposite

  • All Implemented Interfaces:
    Serializable

    public final class SObjectComposite
    extends Object
    implements Serializable
    Executes a series of REST API requests in a single call. You can use the output of one request as the input to a subsequent request. The response bodies and HTTP statuses of the requests are returned in a single response body. The entire request counts as a single call toward your API limits. The requests in a composite call are called subrequests. All subrequests are executed in the context of the same user. In a subrequest’s body, you specify a reference ID that maps to the subrequest’s response. You can then refer to the ID in the url or body fields of later subrequests by using a JavaScript-like reference notation. 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, String) or addGeneric(Method, String, Object, String) methods. To build the batch use:
     
     composite = new SObjectComposite("41.0", true);
    
     // insert operation via an external id
     final Invoice__c_Lookup invoiceLookup = new Invoice__c_Lookup();
     invoiceLookup.setInvoice_External_Id__c("0116");
    
     final Payment__c payment = new Payment__c();
     payment.setInvoice__r(invoiceLookup);
    
     composite.addCreate(payment, "NewPayment1");
     composite.addCreate(payment, "NewPayment2");
     
     
    This will build a composite of two insert operations.
    See Also:
    Serialized Form
    • Field Detail

      • REQUIRED_PAYLOAD_FORMAT

        public static final PayloadFormat REQUIRED_PAYLOAD_FORMAT
    • Constructor Detail

      • SObjectComposite

        public SObjectComposite​(String apiVersion,
                                boolean allOrNone)
        Create new composite 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 Detail

      • addDelete

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

        public SObjectComposite addGeneric​(SObjectComposite.Method method,
                                           String url,
                                           Object richInput,
                                           String referenceId)
        Generic way to add requests to composite 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
      • addGeneric

        public SObjectComposite addGeneric​(SObjectComposite.Method method,
                                           String url,
                                           String referenceId)
        Generic way to add requests to composite. 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
      • addGet

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

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

        public SObjectComposite addGetRelated​(String type,
                                              String id,
                                              String relation,
                                              String referenceId,
                                              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
      • addQuery

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

        public SObjectComposite addQueryAll​(String query,
                                            String referenceId)
        Add retrieval of all SObject records by query to the composite.
        Parameters:
        query - SOQL query to execute
        Returns:
        this batch builder
      • addUpdate

        public SObjectComposite addUpdate​(String type,
                                          String id,
                                          AbstractSObjectBase data,
                                          String referenceId)
        Add update of SObject record to the composite. 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 SObjectComposite addUpdateByExternalId​(String type,
                                                      String fieldName,
                                                      String fieldValue,
                                                      AbstractSObjectBase data,
                                                      String referenceId)
        Add update of SObject record by external identifier to the composite. 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 field value
        data - SObject with fields to change
        Returns:
        this batch builder
      • addUpsertByExternalId

        public SObjectComposite addUpsertByExternalId​(String type,
                                                      String fieldName,
                                                      String fieldValue,
                                                      AbstractSObjectBase data,
                                                      String referenceId)
        Add insert or update of SObject record by external identifier to the composite. 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 field value
        data - SObject with fields to change
        Returns:
        this batch builder
      • getAllOrNone

        public boolean getAllOrNone()
      • getCompositeRequests

        public List<org.apache.camel.component.salesforce.api.dto.composite.CompositeRequest> getCompositeRequests()
        Fetches compose requests contained in this compose request.
        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 composite request, needed for serialization.
        Returns:
        all object types in this composite request