function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alex.AcostaAlex.Acosta 

Salesforce Merge

I have an issue where my my org is uploading a ton of leads at a time via the dataloader. These new leads could potentually be existing accounts / leads and need to be merged to their latest associated record. The issue I'm having is, imagine a batch of 200 records hits my trigger and all have to be merged with older leads. Only 150 DML statements are allowed, and each merge has to be done one at a time which causes an issue. I know the Salesforce API has an object alled MergeRequest which allows you to do a collection of merges within a single call. Has anyone been able to figure out an effiecent way of achieving this? Also, does anyone know if the API can be called within a trigger / apex? 

sfdcfoxsfdcfox

You'll probably need to use two @future calls. You can split your records in half (thus, 100 per half), call two future methods (the same one twice, each with a different list), and have that method perform the merge. I don't know of a way to perform a mass merge in Apex Code, nor can you (easily) call the API directly from Apex Code (it's actually discouraged to even attempt to do so).