[SalesForce] Contact matching rules and Duplicate rules bypass using apex

I have a custom matching rule set up for contact. I used that in my contact duplicate rule. When users fill contact data and try to save contact SFDC shows warning with duplicate result. but user can click on save button second time and it allows to save the record.

I know that we can bypass duplicate rules using apex. But I am trying to create a contact using apex. When I get duplicate match I am able to show the duplicate Result in UI as warning, but I want to save the contact when user click on "Save Contact" button second time just like in native lightning experience.

Best Answer

You would need to track if the duplicate warning has already been shown once, and if so, then use the normal method of bypassing duplicates in Apex. In Lightning, it would look like:

<aura:attribute name="duplicateConfirm" type="Boolean" default="false" />

...

saveRecord: function(component, event, helper) {
  var record = component.get("v.record"),
      dupConfirm = component.get("v.duplicateConfirm"),
      action = component.get("c.saveContactRecord");
  action.setParams( { dupConfirm: dupConfirm, record: record });
  action.setCallback(this, function(result) {
    // check if successful, else...
    component.set("v.duplicateConfirm", true);
    // ...
  });
  $A.enqueueAction(action);
}
Related Topic