Thiru
Thiru

Reputation: 424

How to convert salesforce select query response into readable format in mule?

I query the data(10 - 20 records) from salesforce contact object and from that i need to capture id value into the variable. to do that i'm setting payload as #[org.apache.commons.collections.IteratorUtils.toList(payload)] but not working.

PFB is the sample code:

<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> 

Getting below error message at set payload:

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)

Upvotes: 0

Views: 811

Answers (1)

JoostD
JoostD

Reputation: 744

Why are you trying to Set the Payload is such a 'creative' way, not necessary and is not going to work either.

The SalesForce connector output is of type org.mule.streaming.ConsumerIterator which can be read directly by a For Each scope, so this already is a collection.

Remove the Set Payload and see if that works, if you debug you should see the behaviour, I've just tested this and this works.

Upvotes: 1

Related Questions