Need to Merge Apex Accounts? Follow This Easy Guide!

Date:

Share post:

Okay, so today I wanted to figure out how to merge some Apex accounts. I had a few duplicate accounts floating around in my Salesforce org, and it was starting to get messy. Time to clean things up!

Need to Merge Apex Accounts? Follow This Easy Guide!

Finding the Duplicates

First things first, I needed to find those pesky duplicate accounts. I started by running a few reports. I looked at accounts created around the same time, accounts with similar names, and accounts with matching website addresses. This gave me a good starting point.

I also used the “Find Duplicates” feature in Salesforce. You know, the one you can sometimes see when you create or edit record. It’s not always perfect, but it helped me catch a few obvious ones.

Choosing the Master Record

Once I had my list of potential duplicates, I needed to decide which account would be the “master” record – the one I’d keep. This was a bit tricky. I compared things like:

  • Account creation date: Usually, the older account is the better one to keep.
  • Number of related contacts and opportunities: Which account had more activity?
  • Completeness of data: Which account had more fields filled in with accurate information?

I picked the account that seemed to be the most complete and active. It’s kind of like choosing the “main” profile when you have multiple social media accounts.

Merging Accounts using Apex code

I prepared and triggered Apex code snippet as following steps:

Need to Merge Apex Accounts? Follow This Easy Guide!
  1. Open the Developer Console.
  2. Open the Execute Anonymous Window.
  3. Paste the Apex code below and modify the Account Ids.

//Master record Id, and duplicate record Id;

Account masterAcct = [SELECT Id FROM Account WHERE Id = '0012v00002STkXXXX'];

Account duplicateAcct = [SELECT Id FROM Account WHERE Id = '0012v00002STkYYYY'];

try {

//'masterAcct' will be remained and other account record will merge to it.

Need to Merge Apex Accounts? Follow This Easy Guide!

merge masterAcct duplicateAcct;

catch(DMLException e) {

//Handle the exception.

Double-Checking Everything

After merging, I double-checked everything. I made sure all the related contacts, opportunities, and other data were now associated with the master account. I also checked for any weirdness or inconsistencies. It’s always good to be thorough!

It took a little bit of time, but I finally got those accounts merged! My Salesforce org is feeling a bit cleaner now. It’s like decluttering your closet – a little effort, but so worth it in the end.

Need to Merge Apex Accounts? Follow This Easy Guide!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related articles

Easy Peasy 124 lbs to kg Conversion: We Show You How It Is Done for Everyone.

Alright, so today, I found myself needing to switch 124 pounds over to kilograms. It’s one of those...

Remember the awesome 1993 new york yankees roster? Relive the glory with every player name listed!

So, the other day, I got to thinking about baseball from a while back, specifically the early 90s....

Bronny James Jail news: Did LeBrons son really get into trouble? Find out the actual truth here.

My Encounter with the “Bronny James Jail” Story Alright, so the other day, this “Bronny James jail” thing popped...

What is the Bleacher Report class action settlement? Get the easy details you need to know.

So, I heard some buzz about this Bleacher Report class action settlement thing a while back. You know...