0

I am facing one issue that even if Duplicate Rule is defined on the Contact Object still I am able to insert duplicate Contact records in bulk from apex. This is because the contacts which I am trying to insert thru Apex that same contact is not yet present in Salesforce, so when I try inserting the multiple Contacts with same information thru apex it will not error out. Once contacts are inserted in SF and now if I try to insert duplicates , apex will error out saying there is already a Duplicate Contact created.

Is there a way to check if the list of Contact records already contain Duplicate Contacts based on Duplicate Rule defined?

1 Answer 1

1

Duplicate rules only compare to existing contacts. If you have duplicates within the list of contacts to be inserted, you will have to write code to detect them, and that could be very difficult.

If these inserts are occurring due to a data import, then a possible workaround is to adjust the import batch size to 1. Thus if there are duplicates within your insert list, the first one will be created but the rest will be rejected. Be very cautious with this workaround since this will consume an API call per import row.

2
  • "is difficult" depends on the complexity of the duplicate rule
    – cropredy
    Sep 14, 2020 at 1:18
  • @David Cheng, these insertions are happening in a batch class where I am inserting Contacts in bulk, but it would be difficult to check duplicate contacts within the logic right because I have to then check what Standard Duplicate Rule has what the custom Duplicate rule has and then based on their criteria I have to implement the same within code but what if the duplicate rule is later modified? Then I have to modify my code also to have those criteria defined.
    – sfdc07
    Sep 14, 2020 at 6:47

You must log in to answer this question.

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