How can i merge duplicate contacts under original contact. Orginal Contact : The contact which was created first is an original contact And we have to merge all duplicate contact in that original contact

1 Answer 1


Check the documentation. SOmething like this.

Contact master = [select id, firstname from contact where id = '123'];
List<Contact> duplicates = [select id from contact where firstname = master.firstname];
Database.MergeResult[] results = Database.merge(master, duplicates, false);
  • 1
    there are some limitations with the above -- duplicates can only be max size 2; your second query will fetch the original master record (it should avoid that in the filter; also needs bind variables); OP also asked for master being the earliest created Contact
    – cropredy
    Aug 6, 2021 at 18:19

This site is temporarily in read-only mode and not accepting new answers.

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