Create a message flow to retrieve all Account records from a Salesforce system by using a SalesforceRequest node.
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.
Follow these steps to create the required message flow:
For information about how to create message flows, see Creating a message flow.
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.
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.
<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.