You need to sign in to do that
Don't have an account?

Merge not working on Contacts and Leads
Hi All,
I am trying to Merge Contacts and Leads using the code example given below for Accounts.
List<Account> ls = new List<Account>{new Account(name='Acme Inc.'),new Account(name='Acme')};
insert ls;
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];
try {
merge masterAcct mergeAcct;
} catch (DmlException e) {
// Process exception here
}
The above code works but when I code on similar lines and change Account to Lead or Contact. I get the error:
Compile Error: Field is not writeable: Contact.Name at line 66.....
Here is what I tried:
List<Contact> ls = new List<Contact>{new Contact(name='Classic Inc.'),new Contact(name='Classic')};
insert ls;
Contact masterAcct = [select id, name from contact where name = 'Classic Inc.' limit 1];
Contact mergeAcct = [select id, name from contact where name = 'Classic' limit 1];
try {
merge masterAcct mergeAcct;
} catch (DmlException e) {
// Process exception here
}
Thankjs
Hector...
use FirstName and LastName instead of Name and it should work. name is a merge field combinging the two (plus salutation & suffix).