Class SObjectBatch
- 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, useaddGeneric(Method, String)
oraddGeneric(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"); }
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SObjectBatch.Method
-
Constructor Summary
Constructors Constructor Description SObjectBatch(String apiVersion)
Create new batch request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SObjectBatch
addCreate(AbstractDescribedSObjectBase data)
Add create SObject to the batch request.SObjectBatch
addDelete(String type, String id)
Add delete SObject with identifier to the batch request.SObjectBatch
addGeneric(SObjectBatch.Method method, String url)
Generic way to add requests to batch.SObjectBatch
addGeneric(SObjectBatch.Method method, String url, Object richInput)
Generic way to add requests to batch withrichInput
payload.SObjectBatch
addGet(String type, String id, String... fields)
Add field retrieval of an SObject by identifier to the batch request.SObjectBatch
addGetByExternalId(String type, String fieldName, String fieldValue)
Add field retrieval of an SObject by external identifier to the batch request.SObjectBatch
addGetRelated(String type, String id, String relation, String... fields)
Add retrieval of related SObject fields by identifier.SObjectBatch
addLimits()
Add retrieval of limits to the batch.SObjectBatch
addQuery(String query)
Add retrieval of SObject records by query to the batch.SObjectBatch
addQueryAll(String query)
Add retrieval of all SObject records by query to the batch.SObjectBatch
addSearch(String searchString)
Add retrieval of SObject records by search to the batch.SObjectBatch
addUpdate(String type, String id, AbstractSObjectBase data)
Add update of SObject record to the batch.SObjectBatch
addUpdateByExternalId(String type, String fieldName, String fieldValue, AbstractSObjectBase data)
Add update of SObject record by external identifier to the batch.SObjectBatch
addUpsertByExternalId(String type, String fieldName, String fieldValue, AbstractSObjectBase data)
Add insert or update of SObject record by external identifier to the batch.List<org.apache.camel.component.salesforce.api.dto.composite.BatchRequest>
getBatchRequests()
Fetches batch requests contained in this batch.Version
getVersion()
Version of Salesforce API for this batch request.Class[]
objectTypes()
Returns all object types nested within this batch, needed for serialization.
-
-
-
Constructor Detail
-
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 Detail
-
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 SObjectid
- 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 methodurl
- 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 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
-
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 SObjectid
- identifier of SObjectfields
- 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 SObjectfieldName
- external identifier field namefieldValue
- 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 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
-
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 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 SObjectBatch addUpdateByExternalId(String type, String fieldName, String fieldValue, AbstractSObjectBase data)
Add update of SObject record by external identifier to the batch. 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 valuedata
- 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 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 valuedata
- 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
-
-