我正试图在Salesforce中创建订单。我在工作流程中创建了一个订单,现在我正在尝试分配与订单关联的产品,因此我尝试使用Mule 3.7.3将订单商品插入Salesforce。
我的工作流程当前返回以下错误:
********************************************************************************
Message : Exception while executing:
payload.OrderItems.records map ((record , indexOfRecord) -> {
^
Type mismatch
found :name, :string
required :name, :object
Type : com.mulesoft.weave.mule.exception.WeaveExecutionException
Code : MULE_ERROR--2
********************************************************************************
Exception stack is:
1. Type mismatch
found :name, :string
required :name, :object (com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchException)
com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchNode:65 (null)
2. Exception while executing:
payload.OrderItems.records map ((record , indexOfRecord) -> {
^
Type mismatch
found :name, :string
required :name, :object (com.mulesoft.weave.mule.exception.WeaveExecutionException)
com.mulesoft.weave.mule.WeaveMessageProcessor:124 (null)
********************************************************************************
Root Exception stack trace:
com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchException: Type mismatch
found :name, :string
required :name, :object
工作流的有效负载来自Salesforce网站: https://developer.salesforce.com/docs/atlas.en-us.api_placeorder.meta/api_placeorder/sforce_placeorder_rest_api_place_order_account.htm 并且转换消息在预览中显示没有错误的结果,但在运行工作流时失败。
有人可以帮忙吗?
有效载荷:
{
"order": {
"attributes": {
"type": "Order"
},
"EffectiveDate": "2016-10-18",
"Status": "Draft",
"billingCity": "SFO-Inside-OrderEntity-1",
"accountId": "0012400000LKPfzAAH",
"Pricebook2Id": "01s24000002JoD1AAK",
"OrderItems": {
"records": [{
"attributes": {
"type": "OrderItem"
},
"PricebookEntryId": "01u24000001rauFAAQ",
"quantity": "1",
"UnitPrice": "15.99"
}]
}
}
}
Mule XML工作流程:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="order-flow-httpListenerConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" basePath="/api"/>
<apikit:config name="order-flow-config" raml="order-flow.raml" consoleEnabled="true" consolePath="console" doc:name="Router"/>
<sfdc:config name="Salesforce__Basic_Authentication" username="${sf.username}" password="${sf.password}" securityToken="${sf.token}" doc:name="Salesforce: Basic Authentication"/>
<apikit:config name="Router" raml="order-flow.raml" consoleEnabled="true" consolePath="console" doc:name="Router">
<apikit:flow-mapping resource="/orders/order" action="post" content-type="application/json" flow-ref="post:/orders/order:order-flow-config"/>
</apikit:config>
<flow name="order-flow-main">
<http:listener config-ref="order-flow-httpListenerConfig" path="/*" doc:name="HTTP"/>
<apikit:router config-ref="Router" doc:name="APIkit Router"/>
<exception-strategy ref="order-flow-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
</flow>
<flow name="post:/orders/order:order-flow-config">
<set-payload value="{"order":{"attributes":{"type":"Order"},"EffectiveDate":"2016-10-18","Status":"Draft","billingCity":"SFO-Inside-OrderEntity-1","accountId":"0012400000LKPfzAAH","Pricebook2Id":"01s24000002JoD1AAK","OrderItems":{"records":[{"attributes":{"type":"OrderItem"},"PricebookEntryId":"01u24000001rauFAAQ","quantity":"1","UnitPrice":"15.99"}]}}}" mimeType="application/json" doc:name="Set Payload"/>
<dw:transform-message metadata:id="054c5e6b-272f-4970-8c1c-d97cd802e792" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
ContractId: "80024000000OhfWAAS",
AccountId: payload.order.accountId,
Pricebook2Id: payload.order.Pricebook2Id,
EffectiveDate: payload.order.EffectiveDate as :date,
Status: payload.order.Status,
Type: payload.order.attributes.type,
BillingCity: payload.order.billingCity
}]]></dw:set-payload>
</dw:transform-message>
<sfdc:create-single config-ref="Salesforce__Basic_Authentication" doc:name="Salesforce" type="Order">
<sfdc:object ref="#[payload]"/>
</sfdc:create-single>
<set-variable variableName="varOrderId" value="#[payload.id]" doc:name="Set Order Id"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<set-payload value="{"OrderItems":{"records":[{"attributes":{"type":"OrderItem"},"PricebookEntryId":"01u24000001rauFAAQ","quantity":"1","UnitPrice":"15.99"}]}}}" doc:name="Set Payload"/>
<dw:transform-message metadata:id="a38edabd-4deb-413f-8bcb-5691e64bc230" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload.OrderItems.records map ((record , indexOfRecord) -> {
OrderId: flowVars.varOrderId,
UnitPrice: record.UnitPrice
})]]></dw:set-payload>
</dw:transform-message>
<sfdc:create config-ref="Salesforce__Basic_Authentication" type="OrderItem" doc:name="Salesforce">
<sfdc:objects ref="#[payload]"/>
</sfdc:create>
<object-to-string-transformer doc:name="Object to String"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
<apikit:mapping-exception-strategy name="order-flow-apiKitGlobalExceptionMapping">
<apikit:mapping statusCode="404">
<apikit:exception value="org.mule.module.apikit.exception.NotFoundException" />
<set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
<set-payload value="{ "message": "Resource not found" }" doc:name="Set Payload"/>
</apikit:mapping>
<apikit:mapping statusCode="405">
<apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException" />
<set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
<set-payload value="{ "message": "Method not allowed" }" doc:name="Set Payload"/>
</apikit:mapping>
<apikit:mapping statusCode="415">
<apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException" />
<set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
<set-payload value="{ "message": "Unsupported media type" }" doc:name="Set Payload"/>
</apikit:mapping>
<apikit:mapping statusCode="406">
<apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException" />
<set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
<set-payload value="{ "message": "Not acceptable" }" doc:name="Set Payload"/>
</apikit:mapping>
<apikit:mapping statusCode="400">
<apikit:exception value="org.mule.module.apikit.exception.BadRequestException" />
<set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
<set-payload value="{ "message": "Bad request" }" doc:name="Set Payload"/>
</apikit:mapping>
</apikit:mapping-exception-strategy>
</mule>
由于
答案 0 :(得分:0)
您收到此错误,因为您将有效负载设置为字符串并尝试以JSON身份进行访问。要么在设置有效负载上设置mime类型,要么像
那样设置数据编织试试这个
<set-payload mimeType="application/json" value="{"OrderItems":{"records":[{"attributes":{"type":"OrderItem"},"PricebookEntryId":"01u24000001rauFAAQ","quantity":"1","UnitPrice":"15.99"}]}}}" doc:name="Set Payload" />
或者
<dw:transform-message doc:name="Transform Message">
<dw:input-payload mimeType="application/json" />
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
%var timeZone = now as :datetime as :string {format:"z"}
---
payload.OrderItems.records map ((record , indexOfRecord) -> {
OrderId: flowVars.varOrderId,
UnitPrice: record.UnitPrice
}) ]]></dw:set-payload>
</dw:transform-message>
希望这有帮助。