Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Maven users will need to add the following dependency to their pom.xml for this component:

Code Block
xml
xml

<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

Code Block

salesforce:topic?options

You can append query options to the URI in the following format, ?option=value&option=value&...

...

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.

Code Block

	...to("salesforce:upsertSObject?sObjectIdName=Name")...

...

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.

Code Block

	...to("salesforce:createBatchJob")..

...

To create and subscribe to a topic

Code Block

	from("salesforce:CamelTestTopic?notifyForFields=ALL&notifyForOperations=ALL&sObjectName=Merchandise__c&updateTopic=true&sObjectQuery=SELECT Id, Name FROM Merchandise__c")...

To subscribe to an existing topic

Code Block

	from("salesforce:CamelTestTopic&sObjectName=Merchandise__c")...

Examples

Uploading a document to a ContentWorkspace

Create the ContentVersion in Java, using a Processor instance:

Code Block
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);
	}

	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:

Code Block
	from("file:///home/camel/library")
		.to(new ContentProcessor())
		.to("salesforce:createSObject"); 

Camel Salesforce Maven Plugin

...

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:

Code Block

	mvn camel-salesforce:generate -DclientId=<clientid> -DclientSecret=<clientsecret> -DuserName=<username> -Dpassword=<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.

Include Page
Endpoint See Also
Endpoint See Also