Available as of Camel 2.12
This component supports producer and consumer endpoints to communicate with Salesforce using Java DTOs. There is a companion maven plugin Camel Salesforce Plugin that generates these DTOs (see further below).
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-salesforce</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>The URI scheme for a salesforce component is as follows
salesforce:topic?options
You can append query options to the URI in the following format,
?option=value&option=value&…
Table of Contents
The component supports the following Salesforce APIs
Producer endpoints can use the following APIs. Most of the APIs process one record at a time, the Query API can retrieve multiple Records.
For example, 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.
The response message will either be null if an existing record was
updated, or CreateSObjectResult with an id of the new record, or a
list of errors while creating the new object.
...to("salesforce:upsertSObject?sObjectIdName=Name")...Producer endpoints can use the following APIs. All Job data formats, i.e. xml, csv, zip/xml, and zip/csv are supported. The request and response have to be marshalled/unmarshalled by the route. Usually the request will be some stream source like a CSV file, and the response may also be saved to a file to be correlated with the request.
For example, the following producer endpoint uses the createBatch API to
create a Job Batch. The in message must contain a body that can be converted into an
InputStream (usually UTF-8 CSV or XML content from a file, etc.) and
header fields 'jobId' for the Job and 'contentType' for the Job content
type, which can be XML, CSV, ZIP_XML or ZIP_CSV. The put message body
will contain BatchInfo on success, or throw a SalesforceException on
error.
...to("salesforce:createBatchJob")..Consumer endpoints can use the following sytax for streaming endpoints to receive Salesforce notifications on create/update.
To create and subscribe to a topic
from("salesforce:CamelTestTopic?notifyForFields=ALL¬ifyForOperations=ALL&sObjectName=Merchandise__c&updateTopic=true&sObjectQuery=SELECT Id, Name FROM Merchandise__c")...To subscribe to an existing topic
from("salesforce:CamelTestTopic&sObjectName=Merchandise__c")...Table of Contents
Create the ContentVersion in Java, using a Processor instance:
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.setVersionDataUrl(enc);
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 bytes from the file into a ContentVersion SObject
// for the salesforce component
.to("salesforce:createSObject");Table of Contents
This Maven plugin generates DTOs for the Camel Salesforce.
The Salesforce component supports 16 options which are listed below.
{% raw %}
| Name | Java Type | Description |
|---|---|---|
loginConfig |
| To use the shared SalesforceLoginConfig as login configuration |
config |
| To use the shared SalesforceLoginConfig as configuration |
httpClientProperties |
| Used for configuring HTTP client properties as key/value pairs |
sslContextParameters |
| To configure security using SSLContextParameters |
httpProxyHost |
| To configure HTTP proxy host |
httpProxyPort |
| To configure HTTP proxy port |
httpProxyUsername |
| To configure HTTP proxy username |
httpProxyPassword |
| To configure HTTP proxy password |
isHttpProxySocks4 |
| Enable for Socks4 proxy false by default |
isHttpProxySecure |
| Enable for TLS connections true by default |
httpProxyIncludedAddresses |
| HTTP proxy included addresses |
httpProxyExcludedAddresses |
| HTTP proxy excluded addresses |
httpProxyAuthUri |
| HTTP proxy authentication URI |
httpProxyRealm |
| HTTP proxy authentication realm |
httpProxyUseDigestAuth |
| Use HTTP proxy Digest authentication false by default |
packages |
| Package names to scan for DTO classes (multiple packages can be separated by comma). |
{% endraw %}
The Salesforce component supports 41 endpoint options which are listed below:
{% raw %}
| Name | Group | Default | Java Type | Description |
|---|---|---|---|---|
operationName | common |
| ||
topicName | common |
| ||
apexMethod | common |
| APEX method name | |
apexQueryParams | common |
| Query params for APEX method | |
apexUrl | common |
| APEX method URL | |
apiVersion | common |
| Salesforce API version defaults to SalesforceEndpointConfig.DEFAULT_VERSION | |
backoffIncrement | common |
| Backoff interval increment for Streaming connection restart attempts for failures beyond CometD auto-reconnect. | |
batchId | common |
| Bulk API Batch ID | |
contentType | common |
| Bulk API content type one of XML CSV ZIP_XML ZIP_CSV | |
defaultReplayId | common |
| Default replayId setting if no value is found in link initialReplayIdMap | |
format | common |
| Payload format to use for Salesforce API calls either JSON or XML defaults to JSON | |
httpClient | common |
| Custom Jetty Http Client to use to connect to Salesforce. | |
includeDetails | common |
| Include details in Salesforce1 Analytics report defaults to false. | |
initialReplayIdMap | common |
| Replay IDs to start from per channel name. | |
instanceId | common |
| Salesforce1 Analytics report execution instance ID | |
jobId | common |
| Bulk API Job ID | |
maxBackoff | common |
| Maximum backoff interval for Streaming connection restart attempts for failures beyond CometD auto-reconnect. | |
notifyForFields | common |
| Notify for fields options are ALL REFERENCED SELECT WHERE | |
notifyForOperationCreate | common |
| Notify for create operation defaults to false (API version = 29.0) | |
notifyForOperationDelete | common |
| Notify for delete operation defaults to false (API version = 29.0) | |
notifyForOperations | common |
| Notify for operations options are ALL CREATE EXTENDED UPDATE (API version 29.0) | |
notifyForOperationUndelete | common |
| Notify for un-delete operation defaults to false (API version = 29.0) | |
notifyForOperationUpdate | common |
| Notify for update operation defaults to false (API version = 29.0) | |
objectMapper | common |
| Custom Jackson ObjectMapper to use when serializing/deserializing Salesforce objects. | |
reportId | common |
| Salesforce1 Analytics report Id | |
reportMetadata | common |
| Salesforce1 Analytics report metadata for filtering | |
resultId | common |
| Bulk API Result ID | |
sObjectBlobFieldName | common |
| SObject blob field name | |
sObjectClass | common |
| Fully qualified SObject class name usually generated using camel-salesforce-maven-plugin | |
sObjectFields | common |
| SObject fields to retrieve | |
sObjectId | common |
| SObject ID if required by API | |
sObjectIdName | common |
| SObject external ID field name | |
sObjectIdValue | common |
| SObject external ID field value | |
sObjectName | common |
| SObject name if required or supported by API | |
sObjectQuery | common |
| Salesforce SOQL query string | |
sObjectSearch | common |
| Salesforce SOSL search string | |
updateTopic | common |
|
| Whether to update an existing Push Topic when using the Streaming API defaults to false |
bridgeErrorHandler | consumer |
|
| Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored. |
exceptionHandler | consumer (advanced) |
| To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored. | |
exchangePattern | consumer (advanced) |
| Sets the exchange pattern when the consumer creates an exchange. | |
synchronous | advanced |
|
| Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). |
{% endraw %}
For obvious security reasons it is recommended that the clientId, clientSecret, userName and password fields be not set in the pom.xml. The plugin should be configured for the rest of the properties, and can be executed using the following command:
mvn camel-salesforce:generate -DcamelSalesforce.clientId=<clientid> -DcamelSalesforce.clientSecret=<clientsecret> \
-DcamelSalesforce.userName=<username> -DcamelSalesforce.password=<password>The generated DTOs use Jackson and XStream annotations. All Salesforce field types are supported. Date and time fields are mapped to Joda DateTime, and picklist fields are mapped to generated Java Enumerations.