Create Quote in Salesforce
This section shows how to create a quote in Salesforce via IntegrationManager (IM).
Process Diagram
Step by Step
Prepare the recommended project file structure or download the template files (im-example-salesforce).
Fill in credentials in the configuration file to communicate with Salesforce API via the REST protocol.
Salesforce configuration
salesforce.username=your_salesforce_username salesforce.password=your_salesforce_password salesforce.clientId=your_salesforce_clientId salesforce.clientSecret=your_salesforce_clientSecret salesforce.url=your_salesforce_url
Create a route context in camel-context.xml and the XML file in resources/routes.
Define the salesforceService bean in the file salesForceRoutes.xml in src/main/resources/routes.
Salesforce Service Bean
<bean id="salesforceServiceOAuth" class="net.pricefx.integration.services.salesforce.auth.SalesforceAuthenticationOAuth"> <property name="url" value="${salesforce.url}"/> <property name="clientId" value="${salesforce.clientId}"/> <property name="clientSecret" value="${salesforce.clientSecret}"/> <property name="password" value="${salesforce.password}"/> <property name="username" value="${salesforce.username}"/> </bean> <bean id="salesforceService" class="net.pricefx.integration.services.salesforce.SalesforceService"> <property name="authentication" ref="salesforceServiceOAuth"/> <property name="url" value="${salesforce.url}"/> <property name="version" value="v44.0"/> </bean> <bean id="camelSalesforceService" class="net.pricefx.integration.services.salesforce.ExchangeSalesforceService"> <property name="salesforceService" ref="salesforceService"/> </bean>
Enable IM listening to events from Pricefx.
Pull event configuration
integration.events.enabled=true integration.events.scheduler-delay=60000 integration.events.delay=10000 integration.events.cache-folder=${data.directory}/events integration.events.event-to-route-mapping.ITEM_APPROVED_Q=direct:quoteApproved
Process the ITEM_APPROVED_Q event and collect data from Pricefx.
Define a processor to be able to fetch all data fields from an approved Pricefx quote.
Fetching approved quote
<bean id="fetchQuoteProcessor" class="net.pricefx.integration.processor.FetchQuoteProcessor"/>
Collect data from Pricefx.
Process event
<from uri="direct:quoteApproved"/> <log message="Received event ITEM_APPROVED_Q for item with Name: ${body[data][0][uniqueName]}"/> <setHeader headerName="sourceId"> <simple>${body[data][0][uniqueName]}</simple> </setHeader> <process ref="fetchQuoteProcessor"/> <setProperty propertyName="uniqueName"> <simple>${body[0][uniqueName]}</simple> </setProperty> <setProperty propertyName="externalRef"> <simple>${body[0][externalRef]}</simple> </setProperty>
Build a body for creating a new Salesforce quote.
Body request
<groovy> def map = new HashMap() map.Name = request.body.uniqueName map.OpportunityId = request.body.externalRef map.Status = request.body.quoteStatus return map </groovy>
Marshal the body object by "gson" and call Salesforce API to create a quote.
Create SFDC quote
<marshal ref="gson"/> <log message="Create Quote ${exchangeProperty[externalRef]} with ${body}"/> <toD uri="pfx-salesforce:post?url={{salesforce.url}}&data=${body}&authentication=#salesforceServiceOAuth&version=v44.0&uri=/services/data/v44.0/sobjects/Quote" />
IntegrationManager version 6.0.0