0

I'm trying to merge two account records using Apex merge method but the issue is values are not copied to the master record from the record to be merged. Based on the solution in this thread Merge DML Operation in Apex: why do blank fields of the master record supersede? could you please someone throw some lights on how to copy the values to master record.

Any thoughts or solution will be much appreciated.

1 Answer 1

1

Copying the values can be as simple as:

Map<String, sObjectField> fields = sobjectType.Contact.fields.getMap();
Map<String, Object> losingContactValues = losingContact.getPopulatedFieldsAsMap();
for(String field: losingContactValues.keySet()) {
  if(winningContact.get(field) == null && fields.get(field).getDescribe().isUpdateable()) {
    winningContact.put(field, losingContactValues.get(value));
  }
}
merge winningContact losingContact;

This method presumes that you only want to copy the value if the winning record's field is null.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .