Creating a MergeUp Batch from a List of Ids in ApexLearn how to use Apex to create a MergeUp Batch from a list of ids.Jan 21, 2025Knowledge
InformationArticle BodyPrerequisites At least one MergeUp Template created for each Object type you wish to merge in a batch.An understanding of Salesforce's propreitary server-side language Apex. Overview Salesforce's Apex server-side language provides the ultimate flexiblility and power inside of Salesforce. This walkthrough shows how to use Apex to create a MergeUp Batch from a list of sObject ids. Steps In order to create our batch, we need to get the Id of the MergeUp Template we want to use, and a list of the record Ids we want to include in the batch. In this example, we're going to merge all Accounts with the Type "Customer - Direct". First we query the data we need, and organize it: mergeup__Template__c template = [ SELECT Id FROM mergeup__Template__c WHERE Name = 'Account Template' LIMIT 1 ]; Id templateId = template.Id; List<Id> accountIds = new List<Id>(); for (Account a : [ SELECT Id FROM Account WHERE Type = 'Customer - Direct' ]) { accountIds.add(a.Id); } Next we create our CreateBatchWithIdsParams object and initialize the templateId and recordIds properties: mergeup.CreateBatch_Globals.CreateBatchWithIdsParams params = new mergeup.CreateBatch_Globals.CreateBatchWithIdsParams(); params.templateId = templateId; params.recordIds = accountIds; We can create as many batches at once as we would like by creating more of these params objects. For instance we might want to create another batch that handles Accounts that are of a different Type. For this example we'll stick to creating one batch.Also note that the ids could belong to any sObject type, as long as it is the same type that the MergeUp Template is based on. Lastly, we use the param we created to build a new MergeUp Batch using the static method CreateBatchRecordIds_Invocable.createBatchWithIds(). List<mergeup.CreateBatch_Globals.CreateBatchWithIdsParams> listOfParams = new List<mergeup.CreateBatch_Globals.CreateBatchWithIdsParams>(); listOfParams.add(params); List<mergeup.CreateBatch_Globals.CreateBatchResponse> responses = mergeup.CreateBatchRecordIds_Invocable.createBatchWithIds(listOfParams); Here is the full example code: mergeup__Template__c template = [ SELECT Id FROM mergeup__Template__c WHERE Name = 'Account Template' LIMIT 1 ]; Id templateId = template.Id; List<Id> accountIds = new List<Id>(); for (Account a : [ SELECT Id FROM Account WHERE Type = 'Customer - Direct' ]) { accountIds.add(a.Id); } mergeup.CreateBatch_Globals.CreateBatchWithIdsParams params = new mergeup.CreateBatch_Globals.CreateBatchWithIdsParams(); params.templateId = templateId; params.recordIds = accountIds; List<mergeup.CreateBatch_Globals.CreateBatchWithIdsParams> listOfParams = new List<mergeup.CreateBatch_Globals.CreateBatchWithIdsParams>(); listOfParams.add(params); List<mergeup.CreateBatch_Globals.CreateBatchResponse> responses = mergeup.CreateBatchRecordIds_Invocable.createBatchWithIds(listOfParams); Notes The MergeUp Template used must use a Record type Template Group, and the Object type of the Template Group must match the Object type of the objects whose Ids are being passed in.One of the things you could do using the mergeBatchId from CreateBatch_Globals.CreateBatchResponse is start the MergeUp Batch by changing its status to Started. For more information on starting a MergeUp Batch, see Starting a MergeUp Batch. Next Steps Learn how to start your MergeUp Batch. Starting a MergeUp BatchStarting Multliple MergeUp BatchesScheduling a MergeUp Batch to Start Later Learn other ways to batch merge with MergeUp Generating Multiple Documents Based on a ReportGenerating Multiple Documents from a List of Records in ApexGenerating Multiple Documents with Advanced Customization in Apex Classes and methods used in this walkthrough CreateBatch_Globals.CreateBatchWithIdsParamsCreateBatch_Globals.CreateBatchResponseCreateBatchRecordIds_Invocable.createBatchWithIds() TitleCreating a MergeUp Batch from a List of Ids in ApexURL NameGenerating-Multiple-Documents-from-a-List-of-Ids-in-Apex