3
votes
in this example, i am getting body as null but before there is a log which prints body.please help thank u in advance

Camel- 2.15.1.redhat-621084
fuse-6.2.1
IDE-codeready studio

salesforce.xml 
-----------

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 https://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd              http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd              http://camel.apache.org/schema/blueprint https://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
    <!-- OSGi blueprint property placeholder -->
    <cm:property-placeholder id="placeholder" persistent-id="org.jboss.quickstarts.fuse.salesforce"/>
    <bean
        class="org.apache.camel.component.salesforce.SalesforceComponent" id="salesforce">
        <property name="loginConfig">
            <bean class="org.apache.camel.component.salesforce.SalesforceLoginConfig">
                <property name="loginUrl" value="${loginUrl}"/>
                <property name="clientId" value="${clientId}"/>
                <property name="clientSecret" value="${clientSecret}"/>
                <property name="userName" value="${userName}"/>
                <property name="password" value="${password}"/>
            </bean>
        </property>
        <property name="packages">
            <array>
                <value>com.cg.Pojos</value>
            </array>
        </property>
    </bean>
    <bean class="org.jboss.quickstarts.fuse.salesforce.RouteXml" id="data"/>
    <camelContext id="salesforce-example-context" xmlns="http://camel.apache.org/schema/blueprint">
        <routeBuilder ref="data"/>
    </camelContext>
</blueprint>

Route
-------

from("direct:sale").log("============Received Request from User To get XML===========")
                .pollEnrich("file:C:/jboss-fuse-6.2.1.redhat-084/work/camel-salesforce/input")
                .doTry()
                .unmarshal(xmlDataFormat).log("${body}")
                .bean(JobCardBean.class,"WriteFile")//just for make json
                .bean(JobCardBean.class,"readFile")//just for json to object
                .log("${body}")//till here i got object in body
                .to("salesforce:upsertSObject?sObjectIdName=Name")
                .choice() 
                .when() 
                .simple("${body} != null")
                .log("Created job with result success=${body.success} and errors=${body.errors}")
                .otherwise() 
                .log("Updated job in salesforce") 
                .end();

logs

[route56 ] [to63 ] [direct:sale ] [ 1842]n | [route58 ] [log162 ] [log ] [ 0]n | [route58 ] [pollEnrich23 ] [pollEnrich[file:C:/jboss-fuse-6.2.1.redhat-084/work/camel-salesforce/input] ] [ 1011]n | [route58 ] [doTry20 ] [doTry ] [ 830]n | [route58 ] [unmarshal20 ] [unmarshal[org.apache.camel.model.DataFormatDefinition@1b5fd83] ] [ 3]n | [route58 ] [log163 ] [log ] [ 30]n | [route58 ] [bean35 ] [bean[com.capgemini.beans.JobCardBean@461fb6bd] ] [ 8]n | [route58 ] [bean36 ] [bean[com.capgemini.beans.JobCardBean@5afe909b] ] [ 4]n | [route58 ] [setHeader33 ] [setHeader[CamelHttpQuery] ] [ 0]n | [route58 ] [setHeader34 ] [setHeader[CamelHttpMethod] ] [ 0]n | [route58 ] [log164 ] [log ] [ 1]n | [route58 ] [to66 ] [salesforce:upsertSObject?sObjectIdName=Name ] [ 783]n | n | Exchangen | ---------------------------------------------------------------------------------------------------------------------------------------n | Exchange[ n | Id ID-DIN17000356-51667-1583407046067-12-2 n | ExchangePattern InOut n | Headers {CamelFileAbsolute=true, CamelFileAbsolutePath=C:\jboss-fuse-6.2.1.redhat-084\work\camel-salesforce\input\job.xml, CamelFileContentType=text/xml, CamelFileLastModified=1583322179800, CamelFileLength=330, CamelFileName=job.xml, CamelFileNameConsumed=job.xml, CamelFileNameOnly=job.xml, CamelFileParent=C:\jboss-fuse-6.2.1.redhat-084\work\camel-salesforce\input, CamelFilePath=C:\jboss-fuse-6.2.1.redhat-084\work\camel-salesforce\input\job.xml, CamelFileRelativePath=job.xml, CamelHttpMethod=POST, CamelHttpQuery=_HTTPMethod=PATCH, CamelRedelivered=false, CamelRedeliveryCounter=0, CamelToEndpoint=file://C:/jboss-fuse-6.2.1.redhat-084/work/camel-salesforce/input} n | BodyType null n | Body [Body is null] n | ]n | n | Stacktracen | --------------------------------------------------------------------------------------------------------------------------------------- {message:'Error {400:Bad Request} executing {PATCH:/services/data/v33.0/sobjects/PSA_Job_Master__c/Name/temp}',statusCode:400} at org.apache.camel.component.salesforce.internal.client.AbstractClientBase$1.onResponseComplete(AbstractClientBase.java:140)[314:org.apache.camel.camel-salesforce:2.15.1.redhat-621084]

1
If anyone having other approach to upsert data in salesforce. Please suggest that too - shaiwali

1 Answers

0
votes

I think it's this: PATCH /services/data/v33.0/sobjects/PSA_Job_Master__c/Name/temp. Upsert operation must use a custom external ID field. You can't mark standard Name field as ext id, the checkbox isn't present in UI.

Try making a custom field (probably type = text? whatever works for you), marking it as external id and (optional but recommended) unique. Maybe even populate your old data (copy values from Name to new field?) and then something like

PATCH /services/data/v33.0/sobjects/PSA_Job_Master__c/ExternalID__c/temp

You can experiment in Workbench (Utilities -> REST Explorer), Postman or SoapUI before you modify your job

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm


Edit - to send (and optionally expect response as) XML you need to send right HTTP headers. See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_usage_rest_resources.htm

POST to 
    /services/data/v48.0/sobjects/Account

With headers
    Content-Type: application/xml
    Accept: application/xml
    Authorization: Bearer {session id goes here}

With body    
    <records>
        <Name>Hi Stack</Name>
        <Description>Lorem ipsum...</Description>
    </records>

Should produce something like this (you'll have your required fields, validation rules etc to worry about but still)

<?xml version="1.0" encoding="UTF-8"?>
<Result>
    <id>0013s00000xJsS9AAK</id>
    <success>true</success>
</Result>

Compare it with JSON example and you should have good idea how the message for upsert should be like?