从Mule ESB中的Salesforce Connector解析错误

时间:2014-02-20 08:50:06

标签: mule mule-studio mule-el

我正在使用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和消息。我尝试了各种组合,但我无法得到它。对于例如#[(消息在(flowVars.listErrors中的错误)]。当Salesforce返回错误时,如何获取StatusCode和消息?

1 个答案:

答案 0 :(得分: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>