0

我正在使用 Mule ESB 3.4 CE。我有这个使用 Salesforce 连接器创建联系人的流程。我想解析错误并采取一些措施。

....
<sfdc:create config-ref="Salesforce" type="Contact" doc:name="Create Contacts">
     <sfdc:objects ref="#[payload]"/>
</sfdc:create>
<expression-component doc:name="Get Successful List">flowVars.listSuccess = ($ in payload if $.success=='true')</expression-component>
<expression-component doc:name="Get Failed List">flowVars.listErrors = ($.errors in payload if $.success=='false')</expression-component>

结果如下:

[[SaveResult  errors='{[1][Error  fields='{[1]Email,}'
  message='A contact with this email address already exists.'
  statusCode='FIELD_CUSTOM_VALIDATION_EXCEPTION'
 ]
 ,}'
 id='null'
 success='false'
]
, [SaveResult  errors='{[1][Error  fields='{[1]Email,}'
   message='A contact with this email address already exists.'
   statusCode='FIELD_CUSTOM_VALIDATION_EXCEPTION'
  ]
,}'
id='null'
success='false'
]
]

我能够通过以下表达式组件获取 ID:

<expression-component doc:name="Get Failed List">flowVars.listIds = (Id in payload)</expression-component>

但是,如果出现错误,我无法查看 statusCode 和消息。我尝试了各种组合,但我无法得到它。例如 #[(message in (errors in flowVars.listErrors)]。当 Salesforce 返回错误时,如何获取 StatusCode 和消息?

4

1 回答 1

1

您的 flowVars.listErrors 将包含一个错误数组列表。查看以下组件以获得灵感:

<logger message="#[flowVars.listErrors[0][0].message]" level="INFO" doc:name="Logger"/>

<scripting:component doc:name="Groovy">
   <scripting:script engine="Groovy"><![CDATA[
      flowVars.listErrors.each{it->it.each{it2->println('message:'+it2.message)}}
   ]]></scripting:script>
</scripting:component>
于 2014-02-20T10:25:54.860 回答