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
Anish SinghAnish Singh 

Merge contact of two different account.

I want to merge two different contact by deleting the contact's associated account. My account is encripted because of which i cannot use a standard functionality.
Scenario:
Account (A1) ----> Contact (C1)
Account (A2) ----> Contact (C2)
I want to build a query where C2 gets merged with C1 by deleting A2.

Here is the query that i user, i know its not correct but trying to build. Need your help.


// Queries to get the inserted accounts
Account masterAcct = [SELECT Id, Name FROM Account WHERE Name = 'Acme Inc.' LIMIT 1];
Account mergeAcct = [SELECT Id, Name FROM Account WHERE Name = 'Acme' LIMIT 1];

// Add a contact to the account to be merged
Contact c = new Contact(FirstName='Joe',LastName='Merged'); c.AccountId = mergeAcct.Id;
insert c;

try {
       merge masterAcct mergeAcct;
} catch (DmlException e) {
       // Process exception
       System.debug('An unexpected error has occurred: ' + e.getMessage());
}



Thanks,
Anish Singh