我从salesforce联系对象查询数据(10 - 20条记录),并且我需要将id值捕获到变量中。为此,我将有效负载设置为#[org.apache.commons.collections.IteratorUtils.toList(payload)]但不起作用。
PFB是示例代码:
<flow name="SetFunctionRole-table">
<sfdc:query config-ref="SFA_NOL_CLOUDHUB2" query="dsql:SELECT Id, AccountId,Account_BP_ID__c,Account_BT_Code__c,Birthdate,Department,Email,Fax,FirstName,LastName,MiddleName,MobilePhone,Name FROM Contact WHERE AccountId = '#[flowVars.varCustomer_Id]' ORDER BY AccountId ASC" doc:name="get contacts from AccountId"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<set-payload value="#[org.apache.commons.collections.IteratorUtils.toList(payload)]" doc:name="Set Payload"/>
<foreach collection="#[payload]" doc:name="For Each">
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<set-variable variableName="varContact_id" value="#[payload['Id']]" doc:name="Variable"/>
<sfdc:query-single config-ref="SFA_NOL_CLOUDHUB2" query="dsql:SELECT Function__c,Id FROM Contact_Function_Role__c WHERE Contact__c = '#[flowVars.varContact_id]'" doc:name="Salesforce"/>
<logger message="#['Inserting key:' + flowVars.varContact_id + ' and value: ' + payload.Id]" level="INFO" doc:name="Logger"/>
<objectstore:store config-ref="ObjectStore__Connector" key="#[flowVars.varContact_id]" value-ref="#[payload.Id]" overwrite="true" doc:name="ObjectStore"/>
</foreach>
</flow>
在设置的有效负载下获取以下错误消息:
ERROR 2017-07-24 20:05:50,333 [[ws21.2-prod].SetFunctionRole-table.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Execution of the expression "org.apache.commons.collections.IteratorUtils.toList(payload)" failed. (org.mule.api.expression.ExpressionRuntimeException).
Payload : org.mule.streaming.ConsumerIterator@665c8b2e
Payload Type : org.mule.streaming.ConsumerIterator
Element : /SetFunctionRole-table/processors/2 @ ws21.2-prod:create-prospect.xml:177 (Set Payload)
Element XML : <set-payload value="#[org.apache.commons.collections.IteratorUtils.toList(payload)]" doc:name="Set Payload"></set-payload>
--------------------------------------------------------------------------------
Root Exception stack trace:
[UnexpectedErrorFault [ApiFault exceptionCode='INVALID_OPERATION_WITH_EXPIRED_PASSWORD'
exceptionMessage='The users password has expired, you must call SetPassword before attempting any other API operations'
extendedErrorDetails='{[0]}'
]
]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
答案 0 :(得分:1)
您为什么要设置有效负载是一种“创意”&#39;方式,没有必要,也没有用。
SalesForce连接器输出的类型为org.mule.streaming.ConsumerIterator,可以由For Each范围直接读取,因此这已经是一个集合。
删除Set Payload并查看是否有效,如果您调试,您应该看到行为,我刚刚对此进行了测试,这是有效的。