Example: Retrieving all Account records from Salesforce (no discovery)

Create a message flow to retrieve all Account records from a Salesforce system by using a SalesforceRequest (no discovery) node.

About this task

Note: SalesforceRequest (no discovery) is the new name for the node that was called SalesforceRequest in previous versions of IBM® App Connect Enterprise (up to and including V12.0.4), and it continues to operate in the same way as in previous versions.

In IBM App Connect Enterprise 12.0.5 (and later versions), a new Salesforce Request node is provided, which you configure by using a Connector Discovery wizard to discover and set properties for the Salesforce connector. For information about using this feature, see Using Salesforce with IBM App Connect Enterprise and Salesforce Request node.

This message flow receives an XML message over HTTP using an HTTPInput node, and then uses a SalesforceRequest (no discovery) 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:

  1. Create a message flow containing an HTTPInput node (called GetSFAccounts), a SalesforceRequest (no discovery) (called GetAllAccounts), a Compute node (called CopyAccounts), and an HTTPReply node (called ReplyWithAccount):
    This image shows a message flow containing HTTPInput and HTTPReply nodes, a Compute node, and a SalesforceRequest node.

    For information about how to create message flows, see Creating a message flow.

  2. On the HTTPInput node, set the following properties:
    1. On the Description tab, set the Node name property to GetSFAccounts
    2. On the Basic tab, set the Path suffix for URL property to /sfaccounts
    3. On the Input Message Parsing tab, set the Message domain property to XMLNSC.
  3. On the SalesforceRequest (no discovery) node, set the following properties:
    1. On the Description tab, set the Node name property to GetAllAccounts
    2. On the Basic tab, set the following properties:
      1. Set the Salesforce URL property to https://login.salesforce.com
      2. Set the Operation property to Retrieve
      3. Set the Salesforce object property to Account
      4. Set the Security identity property to SF. For information about configuring the security identity, see Configuring a secure connection to Salesforce.com (no discovery).
      5. Set the Timeout (milliseconds) property to 120000.
    3. On the Result tab, set the following properties:
      1. Set the Output data location property to $OutputLocalEnvironment/SalesforceData
      2. 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 (no discovery) node under LocalEnvironment.SalesforceData.JSON.Data.

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

  5. On the HTTPReply node, set the Node name property (on the Description tab) to ReplyWithAccount.