How To: Clone a Parent Record with Child Records that Reference Each Other
October 22, 2018
How To: Create a Quick Action Lightning Component for Super Clone Pro
January 14, 2019

How To: Run Super Clone Pro from Batch Apex

Sometimes heavy processing requires running Apex logic asynchronously to avoid reaching Salesforce processing limits. Below is an example of how run Super Clone Pro’s methods to Clone a hierarchy or Copy child records in a batch Apex job.

Both batch examples accept parameters of which records should be processed. The batch query selects records to process based on the Ids that were received. The class implements stateful, so it may store error messages in a string. In the Finally method, an email containing the messages is sent to the submitter.

Clone in a Batch

This is an example of how to submit the clone job. The batch class’ constructor accepts a set of record Ids to clone. The submission code builds the set, instantiates the batch class, and passes it to the executeBatch method. The second parameter of “1” indicates that it should process 1 record per batch processing transaction.

 

Copy in a Batch

This is an example of how to submit the copy job. The batch class’ constructor accepts a map of record Ids to clone. The map contains a record id that will be copied to as the key and the record id that will be copied from as the value in the map. The submission code builds the map, instantiates the batch class, and passes it to the executeBatch method. The second parameter of “1” indicates that it should process 1 record per batch processing transaction. The copy contains a little extra processing than the clone because we need to rebuild the map for the API execution.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.