function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Adrian-EAdrian-E 

Duplicate Value Alert - Prompt User to continue

I would like to customize the following trigger to PROMPT the user when a duplicate value is found and ask if he wants to continue. If he clicks yes, then it should save the value

 

 

trigger ContactDuplicateTrigger on Contact (before insert) { for (Contact c : Trigger.new){ Contact[] contacts= [select id from Contact where Email = :c.Email]; if (contacts.size() > 0) { c.LastName.addError('Contact cannot be created - Contact already exists'); } }}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

Triggers don't allow interaction with the UI.

You basically have 2 options that I am aware of:

One, create a "Is duplicate" checkbox on the contact record, if the user doesn't have it checked, and the record is a duplicate, generate an error indicating it is a duplicate and if they want to proceed, they need to check the box and save again.  To prevent possible bad behavior, you could also generate an error if they check the box and it isn't a duplicate (my users would just check it every time if they thought that would be easier).

 

Two, you would have to create a VF page to replace the contact record, with a custom controller, and a custom save method. Then you could do the additional items to prompt the user.

All Answers

JimRaeJimRae

Triggers don't allow interaction with the UI.

You basically have 2 options that I am aware of:

One, create a "Is duplicate" checkbox on the contact record, if the user doesn't have it checked, and the record is a duplicate, generate an error indicating it is a duplicate and if they want to proceed, they need to check the box and save again.  To prevent possible bad behavior, you could also generate an error if they check the box and it isn't a duplicate (my users would just check it every time if they thought that would be easier).

 

Two, you would have to create a VF page to replace the contact record, with a custom controller, and a custom save method. Then you could do the additional items to prompt the user.

This was selected as the best answer
Adrian-EAdrian-E

Is there no possiblity to incorporate JavaScript into the APEX triggers?

I'd hate to have to 'outsource' my contact interface to Visualforce - it will make the maintenance a nightmare  :)

JimRaeJimRae
No, not that I am aware of.  The options I suggested are the only ways that I have been able to figure out this type of use case.
Adrian-EAdrian-E
Thanks!