Message Image  

App Connect

Calling a Delete operation from Salesforce 

Mon July 06, 2020 12:20 PM

This article explores the “delete” functionality that’s available with IBM App Connect Designer by using a delete operation use case for Salesforce.

Scenario

Let’s suppose you have multiple Salesforce instances that you want to synchronize by using two flows:

  • The first flow synchronizes new customer Account objects between two Salesforce instances.
  • The second flow retrieves deleted customer Account objects from the first Salesforce instance so it can delete the corresponding objects from the second Salesforce instance.

We use a custom field called ExternalId to link the Account objects in the Salesforce instances.

How will the flows work?

The flows will synchronize two Salesforce instances that we refer to as SFAccount1 and SFAccount2.

  1. For the first flow, we add a “New account” event as the trigger from the SFAccount1 Salesforce instance, which will create a new Account object in the SFAccount2 Salesforce instance. (These Account objects in the Salesforce instances are linked by the ExternalId custom field mentioned earlier.)

    For more information about creating custom fields in Salesforce, see Create Custom Fields in the Salesforce documentation.
  2. Start the flow (flow 1) and then open the SFAccount1 instance and create an Account object. Flow 1 will create an Account object with the same properties in the SFAccount2 instance.
  3. For the second flow we use the Scheduler node as the event trigger, and set it up to repeat every 1 minute.
  4. We want to delete the Account objects in the SFAccount2 instance that were deleted from the the SFAccount1 instance since the flow last ran. To help do this, we add a Set Variable node where we define a defaultTimecheck variable that takes the value of the Previous event time field from the Scheduler and converts it to milliseconds. We’ll use this variable as a checking condition on further actions. We want to execute the actions that follow only if the value of defaultTimeCheck is greater than zero. During its first operation, the Scheduler always returns the Previous event time as equal to the Epoch time, which is equal to zero.
  5. We add an If node to check that the value of defaultTimeCheck is greater than zero; only then do we allow it to execute the rest of the flow.
  6. Next, we want to retrieve the accounts from the SFAccount1 instance that have been deleted. So we add two “Where” conditions for this retrieve action. The Last Modified Date property should be greater than the Previous event time (mapped from the Scheduler node) and the Deleted property should be true.
  7. We then use a For each node to process each of the retrieved Account objects. We can run the For each node serially or in parallel to process the items.
  8. We retrieve the linked Account object in the SFAcount2 instance by using the ExternalId field reference.
  9. We can now use a delete action to delete any Account object from the SFAccount2 instance, which was deleted from the SFAccount1 instance since the flow last ran. For Salesforce, App Connect provides a “delete by ID” condition and we use that to locate any SFAccount2 Account ID that matches the SFAccount1 Account IDs that were returned by the previous Retrieve accounts action. This retrieve action returns an array, so while mapping the Account ID field in the Delete node, we need to resolve the expression to the [0]th element of that array like this:


  10. We can then start and test this flow. From the SFAccount1 instance, we delete the account that we created as part of flow 1. The Scheduler will trigger flow 2 every minute and then delete the corresponding Account object in the SFAccount2 instance.

#AppConnect
#AppConnect-IBMCloud
#delete
#crud
#deletenode

Statistics

0 Favorited
10 Views
0 Files
0 Shares
0 Downloads