Class SObjectComposite
- java.lang.Object
-
- org.apache.camel.component.salesforce.api.dto.composite.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, useaddGeneric(Method, String, String)
oraddGeneric(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");
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SObjectComposite.Method
-
Field Summary
Fields Modifier and Type Field Description static PayloadFormat
REQUIRED_PAYLOAD_FORMAT
-
Constructor Summary
Constructors Constructor Description SObjectComposite(String apiVersion, boolean allOrNone)
Create new composite request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SObjectComposite
addCreate(AbstractDescribedSObjectBase data, String referenceId)
Add create SObject to the composite request.SObjectComposite
addDelete(String type, String id, String referenceId)
Add delete SObject with identifier to the composite request.SObjectComposite
addGeneric(SObjectComposite.Method method, String url, Object richInput, String referenceId)
Generic way to add requests to composite withrichInput
payload.SObjectComposite
addGeneric(SObjectComposite.Method method, String url, String referenceId)
Generic way to add requests to composite.SObjectComposite
addGet(String type, String id, String referenceId, String... fields)
Add field retrieval of an SObject by identifier to the composite request.SObjectComposite
addGetByExternalId(String type, String fieldName, String fieldValue, String referenceId)
Add field retrieval of an SObject by external identifier to the composite request.SObjectComposite
addGetRelated(String type, String id, String relation, String referenceId, String... fields)
Add retrieval of related SObject fields by identifier.SObjectComposite
addQuery(String query, String referenceId)
Add retrieval of SObject records by query to the composite.SObjectComposite
addQueryAll(String query, String referenceId)
Add retrieval of all SObject records by query to the composite.SObjectComposite
addUpdate(String type, String id, AbstractSObjectBase data, String referenceId)
Add update of SObject record to the composite.SObjectComposite
addUpdateByExternalId(String type, String fieldName, String fieldValue, AbstractSObjectBase data, String referenceId)
Add update of SObject record by external identifier to the composite.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.boolean
getAllOrNone()
List<org.apache.camel.component.salesforce.api.dto.composite.CompositeRequest>
getCompositeRequests()
Fetches compose requests contained in this compose request.Version
getVersion()
Version of Salesforce API for this batch request.Class[]
objectTypes()
Returns all object types nested within this composite request, needed for serialization.
-
-
-
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
-
addCreate
public SObjectComposite addCreate(AbstractDescribedSObjectBase data, String referenceId)
Add create SObject to the composite request.- Parameters:
data
- object to create- Returns:
- this batch builder
-
addDelete
public SObjectComposite addDelete(String type, String id, String referenceId)
Add delete SObject with identifier to the composite request.- Parameters:
type
- type of SObjectid
- 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 withrichInput
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 methodurl
- URL starting from the versionrichInput
- 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 methodurl
- 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 SObjectid
- identifier of SObjectfields
- 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 SObjectfieldName
- external identifier field namefieldValue
- 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 exampleAccount
has a relation toCreatedBy
. To fetch fields from that related object (User
SObject) use:batch.addGetRelated("Account", identifier, "CreatedBy", "Name", "Id")
- Parameters:
type
- type of SObjectid
- identifier of SObjectrelation
- name of the related SObject fieldfields
- 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 givendata
parameter must contain only the fields that need updating and must not contain theId
field. So set any fields tonull
that you do not want changed along withId
field.- Parameters:
type
- type of SObjectid
- identifier of SObjectdata
- 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 givendata
parameter must contain only the fields that need updating and must not contain theId
field. So set any fields tonull
that you do not want changed along withId
field.- Parameters:
type
- type of SObjectfieldName
- name of the field holding the external identifierfieldValue
- external identifier field valuedata
- 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 givendata
parameter must contain only the fields that need updating and must not contain theId
field. So set any fields tonull
that you do not want changed along withId
field.- Parameters:
type
- type of SObjectfieldName
- name of the field holding the external identifierfieldValue
- external identifier field valuedata
- 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
-
-