+ Start a Discussion
Pavan AnnaldasPavan Annaldas 

Merging Contact records using apex is not working

I am create two contact records, one contact is having value in Phone field, another is not having value in Phone field. 

I treated one record as master(Which is not having value in phone field ) another as duplicate.

When Meged using apex, all child records associated with duplicate contact record, are reparented maste contact. But Phone value is not replaced with Duplicate contact record phone value.
Best Answer chosen by Pavan Annaldas
PratikPratik (Salesforce Developers) 
Hi Pavan,

When you merge through Database.merge() method, only the child records will get reparented and the field values will not get copy.  The field values will be as of master record only. 
The Standard Wizard will give this flexibility of choosing the fields values.

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.

All Answers

PratikPratik (Salesforce Developers) 
Hi Pavan,

How you are merging the contacts, is it the standard merge wizard or you have done the customization? if it's customization, please share the code so we can help you.

Thanks,
Pratik
Pavan AnnaldasPavan Annaldas
Hi Prateek,

I'm merging contacts using Apex code.

Please find below code.

Contact con = [select id,fax,phone from contact where id='0039000001LfQNt'];
Contact con2 = [select id,fax,phone from contact where id='0039000001LfQNs'];
database.merge(con, con2);
 
PratikPratik (Salesforce Developers) 
Hi Pavan,

When you merge through Database.merge() method, only the child records will get reparented and the field values will not get copy.  The field values will be as of master record only. 
The Standard Wizard will give this flexibility of choosing the fields values.

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
This was selected as the best answer
Pavan AnnaldasPavan Annaldas
Hi Prateek,

I have more than 10K record in our org, Based on some of the conditions I have to perform merge operation.

By using standard wizard it is difficult. 

Is it possible by using database.Merge() method to copy duplicate record field values to  master record field, If master record field value is null and duplicate record is having value, in field ?

Thanks in advance.
PratikPratik (Salesforce Developers) 
Hi Pavan,

It's not feasible with Database.merge to duplicate record's value in the blank field of master records.

You can try for appexchange app :
https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003IYLlEAO

Thnaks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
PratikPratik (Salesforce Developers) 
Glad it helped!

Thanks,
Pratik