Salesforce和apache Camel更新操作

gdx19jrr  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(211)

在这个例子中,我得到的body为null,但之前有一个打印body的日志。请帮助,提前谢谢。
我也尝试了this answer。从工作台中,我得到了nameiddescription__c,它们将用作该SObject的外部id
我想知道是否有任何方法可以将XML发送到Salesforce。在研发之后,我得到了一个新的错误:

[{"errorCode":"JSON_PARSER_ERROR","message":"Unexpected character ('<' (code 60)): expected a valid value

如果任何人有任何其他方法可用于将外部数据更新插入Salesforce,请提出建议。

  • 驼色-2.15.1.红帽子-621084
  • 保险丝-6.2.1
  • IDE代码就绪工作室
销售团队. 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>

路线

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();
个日志
[route56           ] [to63              ] [direct:sale                                                                   ] [      1842]
[route58           ] [log162            ] [log                                                                           ] [         0]
[route58           ] [pollEnrich23      ] [pollEnrich[file:C:/jboss-fuse-6.2.1.redhat-084/work/camel-salesforce/input]   ] [      1011]
[route58           ] [doTry20           ] [doTry                                                                         ] [       830]
[route58           ] [unmarshal20       ] [unmarshal[org.apache.camel.model.DataFormatDefinition@1b5fd83]                ] [         3]
[route58           ] [log163            ] [log                                                                           ] [        30]
[route58           ] [bean35            ] [bean[com.capgemini.beans.JobCardBean@461fb6bd]                                ] [         8]
[route58           ] [bean36            ] [bean[com.capgemini.beans.JobCardBean@5afe909b]                                ] [         4]
[route58           ] [setHeader33       ] [setHeader[CamelHttpQuery]                                                     ] [         0]
[route58           ] [setHeader34       ] [setHeader[CamelHttpMethod]                                                    ] [         0]
[route58           ] [log164            ] [log                                                                           ] [         1]
[route58           ] [to66              ] [salesforce:upsertSObject?sObjectIdName=Name                                   ] [       783]

Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
    Id                  ID-DIN17000356-51667-1583407046067-12-2
    ExchangePattern     InOut
    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
    }
    BodyType            null
    Body                [Body is null]
]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
{ 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]
o2g1uqev

o2g1uqev1#

我想是这样的:PATCH /services/data/v33.0/sobjects/PSA_Job_Master__c/Name/temp。更新插入操作必须使用自定义外部ID字段。您不能将标准名称字段标记为外部ID,该复选框在UI中不存在。
试着创建一个自定义字段(可能是type = text-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PATCH /services/data/v33.0/sobjects/PSA_Job_Master__c/ExternalID__c/temp
在修改作业之前,可以在Workbench(Utilities -〉REST Explorer)、Postman或SoapUI中进行试验
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm
编辑-发送(也可以期望响应为)需要发送正确HTTP头的XML。请参阅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>

应该会产生类似这样的结果(您需要考虑必填字段、验证规则等,但仍然需要)

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

将它与JSON example进行比较,你应该很清楚upsert的消息应该是什么样的?

相关问题