MuleSoft: Creating Salesforce Objects in Sequence

Figure 1: Wait till Bulk Job is finished

When creating a parent child objects in Salesforce, while using Bulk API, after posting the parent objects for “Upsert” operation, the call for creating the child objects must wait till the Parent Objects Job has finished. Unfortunately, Salesforce does not provide any way to control the sequence of bulk jobs execution. So the solution I came up with as shown in figure 1, is to loop using Try and until successful, pulling the Salesforce for the Bulk Job status and if not successful fail and try again.

  1. The flow starts by calling a Java Static Class (code below) to wait for configurable period before trying to pull the status of the job.

/**

*

*/

package mbccrmgroupsysapi;

/**

* @author moustafa.refaat

*

*/

public class Helpers {

public static void waitDurationMS(long waitTime) {

try {

Thread.sleep(waitTime);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

  1. set the payload to the jobInfo

  2. call get Bulk info API

  1. based on the results create a true/false result if the job completed or not

  2. if the result is false, through a custom error/exception

  3. This will make the until successful keep trying tile the number of trials exhausted waiting the specified period between re-tries

Hope this was helpful to you let me know if you need any help.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: