Salesforce
Since Camel 2.12
Both producer and consumer are supported
This component supports producer and consumer endpoints to communicate with Salesforce using Java DTOs. There is a companion maven plugin that generates these DTOs.
| Developers wishing to contribute to the component are instructed to look at the README.md file on instructions on how to get started and set up your environment for running integration tests. |
Getting Started
Follow these steps to get started with the Salesforce component.
-
Create a salesforce org. If you don’t already have access to a salesforce org, you can create a free developer org.
-
Create a Connected App. In salesforce, go to Setup > Apps > App Manager, then click on New Connected App. Make sure to check Enable OAuth Settings and include relevant OAuth Scopes, including the scope called Perform requests at any time. Click Save.
-
Get the Consumer Key and Consumer Secret. You’ll need these to configure salesforce authentication. View your new connected app, then copy the key and secret and save in a safe place.
-
Add Maven dependency.
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-salesforce</artifactId> </dependency>Spring Boot users should use the starter instead.
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-salesforce-starter</artifactId> </dependency> -
Generate DTOs. Optionally, generate Java DTOs to represent your salesforce objects. This step isn’t a hard requirement per se, but most use cases will benefit from the type safety and auto-completion. Use the maven plugin to generate DTOs for the salesforce objects you’ll be working with.
-
Configure authentication. Using the OAuth key and secret, you generated previously, configure salesforce authentication.
-
Create routes. Starting creating routes that interact with salesforce!
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Salesforce component supports 108 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
APEX method name. | String | ||
Query params for APEX method. | Map | ||
Salesforce API version. | 56.0 | String | |
Backoff interval increment for Streaming connection restart attempts for failures beyond CometD auto-reconnect. | 1000 | long | |
Bulk API Batch ID. | String | ||
Bulk API content type, one of XML, CSV, ZIP_XML, ZIP_CSV. Enum values:
| ContentType | ||
Default replayId setting if no value is found in initialReplayIdMap. | -1 | Long | |
ReplayId to fall back to after an Invalid Replay Id response. | -1 | Long | |
Payload format to use for Salesforce API calls, either JSON or XML, defaults to JSON. As of Camel 3.12, this option only applies to the Raw operation. Enum values:
| PayloadFormat | ||
Custom Jetty Http Client to use to connect to Salesforce. | SalesforceHttpClient | ||
Connection timeout used by the HttpClient when connecting to the Salesforce server. | 60000 | long | |
Timeout used by the HttpClient when waiting for response from the Salesforce server. | 10000 | long | |
Max content length of an HTTP response. | Integer | ||
HTTP request buffer size. May need to be increased for large SOQL queries. | 8192 | Integer | |
Timeout value for HTTP requests. | 60000 | long | |
Include details in Salesforce1 Analytics report, defaults to false. | false | Boolean | |
Replay IDs to start from per channel name. | Map | ||
Salesforce1 Analytics report execution instance ID. | String | ||
Bulk API Job ID. | String | ||
Limit on number of returned records. Applicable to some of the API, check the Salesforce documentation. | Integer | ||
Locator provided by salesforce Bulk 2.0 API for use in getting results for a Query job. | String | ||
Maximum backoff interval for Streaming connection restart attempts for failures beyond CometD auto-reconnect. | 30000 | long | |
The maximum number of records to retrieve per set of results for a Bulk 2.0 Query. The request is still subject to the size limits. If you are working with a very large number of query results, you may experience a timeout before receiving all the data from Salesforce. To prevent a timeout, specify the maximum number of records your client is expecting to receive in the maxRecords parameter. This splits the results into smaller sets with this value as the maximum size. | Integer | ||
Sets the behaviour of 404 not found status received from Salesforce API. Should the body be set to NULL NotFoundBehaviour#NULL or should a exception be signaled on the exchange NotFoundBehaviour#EXCEPTION - the default. Enum values:
| EXCEPTION | NotFoundBehaviour | |
Notify for fields, options are ALL, REFERENCED, SELECT, WHERE. Enum values:
| NotifyForFieldsEnum | ||
Notify for create operation, defaults to false (API version >= 29.0). | false | Boolean | |
Notify for delete operation, defaults to false (API version >= 29.0). | false | Boolean | |
Notify for operations, options are ALL, CREATE, EXTENDED, UPDATE (API version < 29.0). Enum values:
| NotifyForOperationsEnum | ||
Notify for un-delete operation, defaults to false (API version >= 29.0). | false | Boolean | |
Notify for update operation, defaults to false (API version >= 29.0). | false | Boolean | |
Custom Jackson ObjectMapper to use when serializing/deserializing Salesforce objects. | ObjectMapper | ||
In what packages are the generated DTO classes. Typically the classes would be generated using camel-salesforce-maven-plugin. Set it if using the generated DTOs to gain the benefit of using short SObject names in parameters/header values. Multiple packages can be separated by comma. | String | ||
Use PK Chunking. Only for use in original Bulk API. Bulk 2.0 API performs PK chunking automatically, if necessary. | false | Boolean | |
Chunk size for use with PK Chunking. If unspecified, salesforce default is 100,000. Maximum size is 250,000. | Integer | ||
Specifies the parent object when you’re enabling PK chunking for queries on sharing objects. The chunks are based on the parent object’s records rather than the sharing object’s records. For example, when querying on AccountShare, specify Account as the parent object. PK chunking is supported for sharing objects as long as the parent object is supported. | String | ||
Specifies the 15-character or 18-character record ID to be used as the lower boundary for the first chunk. Use this parameter to specify a starting ID when restarting a job that failed between batches. | String | ||
Query Locator provided by salesforce for use when a query results in more records than can be retrieved in a single call. Use this value in a subsequent call to retrieve additional records. | String | ||
Use raw payload String for request and response (either JSON or XML depending on format), instead of DTOs, false by default. | false | boolean | |
Salesforce1 Analytics report Id. | String | ||
Salesforce1 Analytics report metadata for filtering. | ReportMetadata | ||
Bulk API Result ID. | String | ||
SObject blob field name. | String | ||
Fully qualified SObject class name, usually generated using camel-salesforce-maven-plugin. | String | ||
SObject fields to retrieve. | String | ||
SObject ID if required by API. | String | ||
SObject external ID field name. | String | ||
SObject external ID field value. | String | ||
SObject name if required or supported by API. | String | ||
Salesforce SOQL query string. | String | ||
Salesforce SOSL search string. | String | ||
If true, streams SOQL query result and transparently handles subsequent requests if there are multiple pages. Otherwise, results are returned one page at a time. | false | Boolean | |
Whether to update an existing Push Topic when using the Streaming API, defaults to false. | false | boolean | |
Global endpoint configuration - use to set values that are common to all endpoints. | SalesforceEndpointConfig | ||
Used to set any properties that can be configured on the underlying HTTP client. Have a look at properties of SalesforceHttpClient and the Jetty HttpClient for all available options. | Map | ||
Used to set any properties that can be configured on the LongPollingTransport used by the BayeuxClient (CometD) used by the streaming api. | Map | ||
Maximum size of the thread pool used to handle HTTP responses. | 20 | int | |
Size of the thread pool used to handle HTTP responses. | 10 | int | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the pub/sub consumer needs to fallback to the latest replay id when the provided id is not valid. If set to false, the component will keep retrying; in order to treat this as an exception you can use BridgeExceptionHandlerToErrorHandler and handle the exception in the route. | false | boolean | |
Max number of events to receive in a batch from the Pub/Sub API. | 100 | int | |
How to deserialize events consume from the Pub/Sub API. AVRO will try a SpecificRecord subclass if found, otherwise GenericRecord. Enum values:
| AVRO | PubSubDeserializeType | |
Fully qualified class name to deserialize Pub/Sub API event to. | String | ||
Replay preset for Pub/Sub API. Enum values:
| LATEST | ReplayPreset | |
Use thread pool for processing received Salesforce events, for example to process events in parallel. | false | boolean | |
To use a custom thread pool for processing received Salesforce events, for example to process events in parallel. | ExecutorService | ||
Maximum thread pool size size for consumer worker pool. | 20 | int | |
Core thread pool size size for consumer worker pool. | 10 | int | |
Timeout in seconds to validate when a custom pubSubReplayId has been configured, when starting the Camel Salesforce consumer. | 30 | int | |
Composite API option to indicate to rollback all records if any are not successful. | false | boolean | |
APEX method URL. | String | ||
Composite (raw) method. | String | ||
Name of Platform Event, Change Data Capture Event, custom event, etc. | String | ||
EXPANDED: Apache Avro format but doesn’t strictly adhere to the record complex type. COMPACT: Apache Avro, adheres to the specification for the record complex type. This parameter is available in API version 43.0 and later. Enum values:
| EventSchemaFormatEnum | ||
The ID of the event schema. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Comma separated list of message headers to include as HTTP parameters for Raw operation. | String | ||
HTTP method to use for the Raw operation. | String | ||
The portion of the endpoint URL after the domain name. E.g., '/services/data/v52.0/sobjects/Account/'. | String | ||
Comma separated list of message headers to include as query parameters for Raw operation. Do not url-encode values as this will be done automatically. | String | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
A list of addresses for which HTTP proxy server should not be used. | Set | ||
Hostname of the HTTP proxy server to use. | String | ||
A list of addresses for which HTTP proxy server should be used. | Set | ||
Port number of the HTTP proxy server to use. | Integer | ||
If set to true the configures the HTTP proxy to use as a SOCKS4 proxy. | false | boolean | |
Allow the Pub/Sub API client to use the proxy detected by java.net.ProxySelector. If false then no proxy server will be used. | true | boolean | |
Explicit authentication method to be used, one of USERNAME_PASSWORD, REFRESH_TOKEN, CLIENT_CREDENTIALS, or JWT. Salesforce component can auto-determine the authentication method to use from the properties set, set this property to eliminate any ambiguity. Enum values:
| AuthenticationType | ||
Required OAuth Consumer Key of the connected app configured in the Salesforce instance setup. Typically a connected app needs to be configured but one can be provided by installing a package. | String | ||
OAuth Consumer Secret of the connected app configured in the Salesforce instance setup. | String | ||
Used in authentication against the HTTP proxy server, needs to match the URI of the proxy server in order for the httpProxyUsername and httpProxyPassword to be used for authentication. | String | ||
Password to use to authenticate against the HTTP proxy server. | String | ||
Realm of the proxy server, used in preemptive Basic/Digest authentication methods against the HTTP proxy server. | String | ||
If set to false disables the use of TLS when accessing the HTTP proxy. | true | boolean | |
If set to true Digest authentication will be used when authenticating to the HTTP proxy, otherwise Basic authorization method will be used. | false | boolean | |
Username to use to authenticate against the HTTP proxy server. | String | ||
URL of the Salesforce instance used after authentication, by default received from Salesforce on successful authentication. | String | ||
Value to use for the Audience claim (aud) when using OAuth JWT flow. If not set, the login URL will be used, which is appropriate in most cases. | String | ||
KeyStore parameters to use in OAuth JWT flow. The KeyStore should contain only one entry with private key and certificate. Salesforce does not verify the certificate chain, so this can easily be a selfsigned certificate. Make sure that you upload the certificate to the corresponding connected app. | KeyStoreParameters | ||
If set to true prevents the component from authenticating to Salesforce with the start of the component. You would generally set this to the (default) false and authenticate early and be immediately aware of any authentication issues. Lazy login is not supported by salesforce consumers. | false | boolean | |
All authentication configuration in one nested bean, all properties set there can be set directly on the component as well. | SalesforceLoginConfig | ||
Required URL of the Salesforce instance used for authentication, by default set to https://login.salesforce.com. | String | ||
Password used in OAuth flow to gain access to access token. It’s easy to get started with password OAuth flow, but in general one should avoid it as it is deemed less secure than other flows. Make sure that you append security token to the end of the password if using one. | String | ||
Pub/Sub host. | api.pubsub.salesforce.com | String | |
Pub/Sub port. | 7443 | int | |
Refresh token already obtained in the refresh token OAuth flow. One needs to setup a web application and configure a callback URL to receive the refresh token, or configure using the builtin callback at https://login.salesforce.com/services/oauth2/success or https://test.salesforce.com/services/oauth2/success and then retrive the refresh_token from the URL at the end of the flow. Note that in development organizations Salesforce allows hosting the callback web application at localhost. | String | ||
SSL parameters to use, see SSLContextParameters class for all available options. | SSLContextParameters | ||
Enable usage of global SSL context parameters. | false | boolean | |
Username used in OAuth flow to gain access to access token. It’s easy to get started with password OAuth flow, but in general one should avoid it as it is deemed less secure than other flows. | String |
Endpoint Options
The Salesforce endpoint is configured using URI syntax:
salesforce:operationName:topicName
With the following path and query parameters:
Path Parameters (2 parameters)
| Name | Description | Default | Type |
|---|---|---|---|
Required The operation to use. Enum values:
| OperationName | ||
The name of the topic/channel to use. | String |
Query Parameters (71 parameters)
| Name | Description | Default | Type |
|---|---|---|---|
APEX method name. | String | ||
Query params for APEX method. | Map | ||
Salesforce API version. | 56.0 | String | |
Backoff interval increment for Streaming connection restart attempts for failures beyond CometD auto-reconnect. | 1000 | long | |
Bulk API Batch ID. | String | ||
Bulk API content type, one of XML, CSV, ZIP_XML, ZIP_CSV. Enum values:
| ContentType | ||
Default replayId setting if no value is found in initialReplayIdMap. | -1 | Long | |
ReplayId to fall back to after an Invalid Replay Id response. | -1 | Long | |
Payload format to use for Salesforce API calls, either JSON or XML, defaults to JSON. As of Camel 3.12, this option only applies to the Raw operation. Enum values:
| PayloadFormat | ||
Custom Jetty Http Client to use to connect to Salesforce. | SalesforceHttpClient | ||
Include details in Salesforce1 Analytics report, defaults to false. | false | Boolean | |
Replay IDs to start from per channel name. | Map | ||
Salesforce1 Analytics report execution instance ID. | String | ||
Bulk API Job ID. | String | ||
Limit on number of returned records. Applicable to some of the API, check the Salesforce documentation. | Integer | ||
Locator provided by salesforce Bulk 2.0 API for use in getting results for a Query job. | String | ||
Maximum backoff interval for Streaming connection restart attempts for failures beyond CometD auto-reconnect. | 30000 | long | |
The maximum number of records to retrieve per set of results for a Bulk 2.0 Query. The request is still subject to the size limits. If you are working with a very large number of query results, you may experience a timeout before receiving all the data from Salesforce. To prevent a timeout, specify the maximum number of records your client is expecting to receive in the maxRecords parameter. This splits the results into smaller sets with this value as the maximum size. | Integer | ||
Sets the behaviour of 404 not found status received from Salesforce API. Should the body be set to NULL NotFoundBehaviour#NULL or should a exception be signaled on the exchange NotFoundBehaviour#EXCEPTION - the default. Enum values:
| EXCEPTION | NotFoundBehaviour | |
Notify for fields, options are ALL, REFERENCED, SELECT, WHERE. Enum values:
| NotifyForFieldsEnum | ||
Notify for create operation, defaults to false (API version >= 29.0). | false | Boolean | |
Notify for delete operation, defaults to false (API version >= 29.0). | false | Boolean | |
Notify for operations, options are ALL, CREATE, EXTENDED, UPDATE (API version < 29.0). Enum values:
| NotifyForOperationsEnum | ||
Notify for un-delete operation, defaults to false (API version >= 29.0). | false | Boolean | |
Notify for update operation, defaults to false (API version >= 29.0). | false | Boolean | |
Custom Jackson ObjectMapper to use when serializing/deserializing Salesforce objects. | ObjectMapper | ||
Use PK Chunking. Only for use in original Bulk API. Bulk 2.0 API performs PK chunking automatically, if necessary. | false | Boolean | |
Chunk size for use with PK Chunking. If unspecified, salesforce default is 100,000. Maximum size is 250,000. | Integer | ||
Specifies the parent object when you’re enabling PK chunking for queries on sharing objects. The chunks are based on the parent object’s records rather than the sharing object’s records. For example, when querying on AccountShare, specify Account as the parent object. PK chunking is supported for sharing objects as long as the parent object is supported. | String | ||
Specifies the 15-character or 18-character record ID to be used as the lower boundary for the first chunk. Use this parameter to specify a starting ID when restarting a job that failed between batches. | String | ||
Query Locator provided by salesforce for use when a query results in more records than can be retrieved in a single call. Use this value in a subsequent call to retrieve additional records. | String | ||
Use raw payload String for request and response (either JSON or XML depending on format), instead of DTOs, false by default. | false | boolean | |
Salesforce1 Analytics report Id. | String | ||
Salesforce1 Analytics report metadata for filtering. | ReportMetadata | ||
Bulk API Result ID. | String | ||
SObject blob field name. | String | ||
Fully qualified SObject class name, usually generated using camel-salesforce-maven-plugin. | String | ||
SObject fields to retrieve. | String | ||
SObject ID if required by API. | String | ||
SObject external ID field name. | String | ||
SObject external ID field value. | String | ||
SObject name if required or supported by API. | String | ||
Salesforce SOQL query string. | String | ||
Salesforce SOSL search string. | String | ||
If true, streams SOQL query result and transparently handles subsequent requests if there are multiple pages. Otherwise, results are returned one page at a time. | false | Boolean | |
Whether to update an existing Push Topic when using the Streaming API, defaults to false. | false | boolean | |
Whether the pub/sub consumer needs to fallback to the latest replay id when the provided id is not valid. If set to false, the component will keep retrying; in order to treat this as an exception you can use BridgeExceptionHandlerToErrorHandler and handle the exception in the route. | false | boolean | |
Max number of events to receive in a batch from the Pub/Sub API. | 100 | int | |
How to deserialize events consume from the Pub/Sub API. AVRO will try a SpecificRecord subclass if found, otherwise GenericRecord. Enum values:
| AVRO | PubSubDeserializeType | |
Fully qualified class name to deserialize Pub/Sub API event to. | String | ||
The replayId value to use when subscribing to the Pub/Sub API. | String | ||
The replayId value to use when subscribing to the Streaming API. | Long | ||
Replay preset for Pub/Sub API. Enum values:
| LATEST | ReplayPreset | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Use thread pool for processing received Salesforce events, for example to process events in parallel. | false | boolean | |
To use a custom thread pool for processing received Salesforce events, for example to process events in parallel. | ExecutorService | ||
Maximum thread pool size size for consumer worker pool. | 20 | int | |
Core thread pool size size for consumer worker pool. | 10 | int | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
Composite API option to indicate to rollback all records if any are not successful. | false | boolean | |
APEX method URL. | String | ||
Composite (raw) method. | String | ||
Name of Platform Event, Change Data Capture Event, custom event, etc. | String | ||
EXPANDED: Apache Avro format but doesn’t strictly adhere to the record complex type. COMPACT: Apache Avro, adheres to the specification for the record complex type. This parameter is available in API version 43.0 and later. Enum values:
| EventSchemaFormatEnum | ||
The ID of the event schema. | String | ||
Comma separated list of message headers to include as HTTP parameters for Raw operation. | String | ||
HTTP method to use for the Raw operation. | String | ||
The portion of the endpoint URL after the domain name. E.g., '/services/data/v52.0/sobjects/Account/'. | String | ||
Comma separated list of message headers to include as query parameters for Raw operation. Do not url-encode values as this will be done automatically. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean |
Message Headers
The Salesforce component supports 23 message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelSalesforceReplayId (consumer) Constant: | The Streaming API replayId. | Object | |
CamelSalesforceEventUuid (consumer) Constant: | The Streaming API eventUuid. | Object | |
CamelSalesforceChangeEventSchema (consumer) Constant: | The change event schema. | Object | |
CamelSalesforceEventType (consumer) Constant: | The event type. | String | |
CamelSalesforceCommitTimestamp (consumer) Constant: | The commit timestamp. | Object | |
CamelSalesforceCommitUser (consumer) Constant: | The commit user. | Object | |
CamelSalesforceCommitNumber (consumer) Constant: | The commit number. | Object | |
CamelSalesforceRecordIds (consumer) Constant: | The record ids. | Object | |
CamelSalesforceChangeType (consumer) Constant: | The change type. | Object | |
CamelSalesforceChangeOrigin (consumer) Constant: | The change origin. | Object | |
CamelSalesforceTransactionKey (consumer) Constant: | The transaction key. | Object | |
CamelSalesforceSequenceNumber (consumer) Constant: | The sequence number. | Object | |
CamelSalesforceIsTransactionEnd (consumer) Constant: | Is transaction end. | Object | |
CamelSalesforceEntityName (consumer) Constant: | The entity name. | Object | |
CamelSalesforcePlatformEventSchema (consumer) Constant: | The platform event schema. | Object | |
CamelSalesforceCreatedDate (consumer) Constant: | The created date. | ZonedDateTime | |
CamelSalesforceTopicName (consumer) Constant: | The topic name. | String | |
CamelSalesforceChannel (consumer) Constant: | The channel. | String | |
CamelSalesforceClientId (consumer) Constant: | The client id. | String | |
CamelSalesforcePubSubReplayId (consumer) Constant: | The Pub/Sub API replayId. | String | |
CamelSalesforcePubSubEventId (consumer) Constant: | The Pub/Sub API event id. | String | |
CamelSalesforcePubSubRpcId (consumer) Constant: | The Pub/Sub API rpc id. | String | |
Total number of records matching a query. | int |
Usage
Authenticating to Salesforce
The component supports four OAuth authentication flows:
For each of the flows, different sets of properties need to be set:
| Property | Where to find it on Salesforce | Flow |
|---|---|---|
| Connected App, Consumer Key | All flows |
| Connected App, Consumer Secret | Username-Password, Refresh Token, Client Credentials |
| Salesforce user username | Username-Password, JWT Bearer Token |
| Salesforce user password | Username-Password |
| From OAuth flow callback | Refresh Token |
| Connected App, Digital Certificate | JWT Bearer Token |
The component auto determines what flow you’re trying to configure. In order to be explicit, set the authenticationType property.
| Using Username-Password Flow in production is not encouraged. |
| The certificate used in JWT Bearer Token Flow can be a self-signed certificate. The KeyStore holding the certificate and the private key must contain only a single certificate-private key entry. |
General Usage
URI format
When used as a consumer, receiving streaming events, the URI scheme is:
salesforce:subscribe:topic?options
When used as a producer, invoking the Salesforce REST APIs, the URI scheme is:
salesforce:operationName?options
As a general example on using the operations in this salesforce component, the following producer endpoint uses the upsertSObject API, with the sObjectIdName parameter specifying 'Name' as the external id field. The request message body should be an SObject DTO generated using the maven plugin.
...to("salesforce:upsertSObject?sObjectIdName=Name")... Supplying operation parameters as message headers
The operation parameters described in the per-operation tables below (such as sObjectQuery, sObjectName, sObjectId, sObjectSearch, apexUrl, apexMethod, the apexQueryParam. prefix and the Bulk/Analytics/RAW parameters) can be supplied either as endpoint options or as message headers.
| Starting with Camel 4.21, when these parameters are supplied as message headers, the header names follow the standard Prefer referencing the constants in |
Passing in Salesforce headers and fetching Salesforce response headers
There is support to pass Salesforce headers via inbound message headers, header names that start with Sforce or x-sfdc on the Camel message will be passed on in the request, and response headers that start with Sforce will be present in the outbound message headers.
For example, to fetch API limits, you can specify:
Processor implementation to read response headers// in your Camel route set the header before Salesforce endpoint
.setHeader("Sforce-Limit-Info", constant("api-usage"))
.to("salesforce:getGlobalObjects")
.to(myProcessor);
// myProcessor will receive `Sforce-Limit-Info` header on the outbound message
class MyProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
String apiLimits = in.getHeader("Sforce-Limit-Info", String.class);
}
} In addition, HTTP response status code and text are available as headers Exchange.HTTP_RESPONSE_CODE and Exchange.HTTP_RESPONSE_TEXT.
Supported Salesforce APIs
Camel supports the following Salesforce APIs:
Apex REST API
Invoke an Apex REST Web Service method
apexCall
You can expose your Apex class and methods so that external applications can access your code and your application through the REST architecture.
The URI format for invoking Apex REST is:
salesforce:apexCall[/yourApexRestUrl][?options]
You can supply the apexUrl either in the endpoint (see above), or as the apexUrl option as listed in the table below. In either case the Apex URL can contain placeholders in the format of {headerName}. E.g., for the Apex URL MyApexClass/{id}, the value of the header named id will be used to replace the placeholder. If rawPayload is false and neither sObjectClass nor sObjectName are set, Camel will attempt to determine the correct AbstractQueryRecordsBase sublcass based on the response.
| Parameter | Type | Description | Default | Required |
|---|---|---|---|---|
Body |
| In the case of a | ||
|
| The portion of the endpoint URL after | Yes, unless supplied in endpoint | |
|
| The HTTP method (e.g. |
| |
|
| If true, Camel will not serialize the request or response bodies. | false | |
Header: | Object | Headers that override apex parameters passed in the endpoint. | ||
|
| Name of sObject (e.g. | ||
|
| Fully qualified class name used to deserialize the response |
Output
Type: Instance of class supplied in sObjectClass input header.
Sub-Pages
For more details on specific Salesforce APIs, see:
-
REST API - CRUD operations, queries, composite requests, approvals, and more
-
Bulk API - Bulk 2.0 and original Bulk API for large data operations
-
Streaming and Pub/Sub - Platform events, push topics, change data capture, and Pub/Sub API
-
Reports API - Report execution, instances, and results
Miscellaneous Operations
-
raw - Send requests to salesforce and have full, raw control over endpoint, parameters, body, etc.
Raw
raw
Sends HTTP requests to salesforce with full, raw control of all aspects of the call. Any serialization or deserialization of request and response bodies must be performed in the route. The Content-Type HTTP header will be automatically set based on the format option, but this can be overridden with the rawHttpHeaders option.
| Parameter | Type | Description | Default | Required |
|---|---|---|---|---|
Body |
| Body of the HTTP request | ||
|
| The portion of the endpoint URL after the domain name, e.g., '/services/data/v51.0/sobjects/Account/' | x | |
|
| The HTTP method | x | |
|
| Comma separated list of message headers to include as query parameters. Do not url-encode values as this will be done automatically. | ||
|
| Comma separated list of message headers to include as HTTP headers |
Output
Type: InputStream
Query example
In this example we’ll send a query to the REST API. The query must be passed in a URL parameter called "q", so we’ll create a message header called q and tell the raw operation to include that message header as a URL parameter:
from("direct:queryExample")
.setHeader("q", "SELECT Id, LastName FROM Contact")
.to("salesforce:raw?format=JSON&rawMethod=GET&rawQueryParameters=q&rawPath=/services/data/v51.0/query")
// deserialize JSON results or handle in some other way SObject example
In this example, we’ll pass a Contact the REST API in a create operation. Since the raw operation does not perform any serialization, we make sure to pass XML in the message body
from("direct:createAContact")
.setBody(constant("<Contact><LastName>TestLast</LastName></Contact>"))
.to("salesforce:raw?format=XML&rawMethod=POST&rawPath=/services/data/v51.0/sobjects/Contact") The response is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Result>
<id>0034x00000RnV6zAAF</id>
<success>true</success>
</Result> Uploading a document to a ContentWorkspace
Using Binary Fields (Recommended)
For efficient document uploads without base64 encoding overhead, use the binary field approach:
public class ContentProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
ContentVersion cv = new ContentVersion();
ContentWorkspace cw = getWorkspace(exchange);
cv.setFirstPublishLocationId(cw.getId());
cv.setTitle("test document");
cv.setPathOnClient("test_doc.html");
// Use binary field for efficient upload - no base64 encoding needed
InputStream document = message.getBody(InputStream.class);
cv.setVersionDataBinary(document); // Automatically triggers multipart request
message.setBody(cv);
}
protected ContentWorkspace getWorkSpace(Exchange exchange) {
// Look up the content workspace somehow, maybe use enrich() to add it to a
// header that can be extracted here
....
}
} Give the output from the processor to the Salesforce component:
from("file:///home/camel/library")
.to(new ContentProcessor()) // convert file stream into a ContentVersion SObject
// with binary field for efficient upload
.to("salesforce:createSObject"); Using Base64 Encoding (Legacy)
The traditional base64 encoding approach is still supported for backward compatibility:
public class ContentProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
ContentVersion cv = new ContentVersion();
ContentWorkspace cw = getWorkspace(exchange);
cv.setFirstPublishLocationId(cw.getId());
cv.setTitle("test document");
cv.setPathOnClient("test_doc.html");
byte[] document = message.getBody(byte[].class);
ObjectMapper mapper = new ObjectMapper();
String enc = mapper.convertValue(document, String.class);
cv.setVersionData(enc); // Uses base64 encoding and standard JSON request
message.setBody(cv);
}
protected ContentWorkspace getWorkSpace(Exchange exchange) {
// Look up the content workspace somehow, maybe use enrich() to add it to a
// header that can be extracted here
....
}
} Generating SOQL query strings
org.apache.camel.component.salesforce.api.utils.QueryHelper contains helper methods to generate SOQL queries. For instance, to fetch all custom fields from Account SObject, you can generate the SOQL SELECT by invoking:
String allCustomFieldsQuery = QueryHelper.queryToFetchFilteredFieldsOf(new Account(), SObjectField::isCustom); Camel Salesforce Maven Plugin
The Maven plugin generates Java DTOs to represent salesforce objects.
Please refer to README.md for details on how to use the plugin.