Example: Retrieving all Account records from Salesforce
Create a message flow to retrieve all Account records from a Salesforce system by using a SalesforceRequest node.
About this task
This message flow receives an XML message over HTTP using
an HTTPInput node, and
then uses a SalesforceRequest node
to send a Retrieve
request to Salesforce to retrieve
all Account records. A Compute node
then uses ESQL to move data for each Account into an XML reply message
that is returned to the calling client application.
Procedure
Follow these steps to create the required message flow:
- Create a message flow containing an HTTPInput node (called
GetSFAccounts
), a SalesforceRequest (calledGetAllAccounts
), a Compute node (calledCopyAccounts
), and an HTTPReply node (calledReplyWithAccount
):For information about how to create message flows, see Creating a message flow.
- On the HTTPInput node,
set the following properties:
- On the Description tab, set the Node name property to GetSFAccounts
- On the Basic tab, set the Path suffix for URL property to /sfaccounts
- On the Input Message Parsing tab, set the Message domain property to XMLNSC.
- On the SalesforceRequest node,
set the following properties:
- On the Description tab, set the Node name property to GetAllAccounts
- On the Basic tab, set the following
properties:
- Set the Salesforce URL property to https://login.salesforce.com
- Set the Operation property to Retrieve
- Set the Salesforce object property to Account
- Set the Security identity property to SF. For information about configuring the security identity, see Configuring a secure connection to Salesforce.com.
- Set the Timeout (milliseconds) property to 120000.
- On the Result tab, set the following
properties:
- Set the Output data location property to $OutputLocalEnvironment/SalesforceData
- Select the Copy local environment property.
The Account records that are returned from the Salesforce system are populated into the output message tree from the SalesforceRequest node under LocalEnvironment.SalesforceData.JSON.Data.
- On the Compute node,
specify the following ESQL statements:
CREATE COMPUTE MODULE GetAllSalesForceAccounts_Compute CREATE FUNCTION Main() RETURNS BOOLEAN BEGIN CALL CopyMessageHeaders(); DECLARE ptrSalesForceAccounts REFERENCE TO InputLocalEnvironment.SalesforceData.JSON.Data; CREATE FIELD OutputRoot.XMLNSC.SalesforceAccounts; DECLARE ptrNewAccount REFERENCE TO OutputRoot.XMLNSC.SalesforceAccounts; MOVE ptrSalesForceAccounts FIRSTCHILD TYPE Name NAME 'Item'; WHILE lastmove(ptrSalesForceAccounts) DO -- An Account was returned from Salesforce so populate a child element -- called Account as the last child of OutputRoot.XMLNSC.SalesforceAccounts with the -- Name, Type, BillingStreet and BillingCity of the returned account data CREATE LASTCHILD OF ptrNewAccount NAME 'Account'; MOVE ptrNewAccount LASTCHILD; CREATE LASTCHILD OF ptrNewAccount NAME 'Name' VALUE ptrSalesForceAccounts.Name; CREATE LASTCHILD OF ptrNewAccount NAME 'Type' VALUE ptrSalesForceAccounts.Type; CREATE LASTCHILD OF ptrNewAccount NAME 'BillingStreet' VALUE ptrSalesForceAccounts.BillingStreet; CREATE LASTCHILD OF ptrNewAccount NAME 'BillingCity' VALUE ptrSalesForceAccounts.BillingCity; MOVE ptrSalesForceAccounts NEXTSIBLING REPEAT TYPE NAME; MOVE ptrNewAccount PARENT; END WHILE; RETURN TRUE; END; CREATE PROCEDURE CopyMessageHeaders() BEGIN DECLARE I INTEGER 1; DECLARE J INTEGER; SET J = CARDINALITY(InputRoot.*[]); WHILE I < J DO SET OutputRoot.*[I] = InputRoot.*[I]; SET I = I + 1; END WHILE; END; END MODULE;
The Compute node moves the Name, Type, BillingStreet, and BillingCity fields for each Account into an XML reply message, which is returned to the calling client application by using the ESQL statements defined on the node.
The format of the XML message that is returned is shown in the following example:<SalesforceAccounts> <Account> <Name>....</Name> <Type>....</Type> <BillingStreet>....</BillingStreet> <BillingCity> … .</BillingCity> </Account> <Account> <Name>....</Name> <Type>....</Type> <BillingStreet>....</BillingStreet> <BillingCity> … .</BillingCity> </Account> </SalesforceAccounts>
For more information about specifying the ESQL statements, see Compute node.
- On the HTTPReply node, set the Node name property (on the Description tab) to ReplyWithAccount.