Write a trigger on Contact to Prevent the user to create duplicate Contact based on Phone if Phone number is already exist on related account in Salesforce | Apex trigger on Contact to do not allow create duplicate contact based Phone number if the contact with same phone exists in related account in Salesforce

  • Before triggers are used to update or validate record values before they’re saved to the database.
  • After triggers are used to access field values that are set by the system (such as a record’s Id or LastModifiedDate field), and to affect changes in other records, such as logging into an audit table or firing asynchronous events with a queue. The records that fire the after trigger are read-only.

Create Apex Trigger →

Step 1:- Create Apex Trigger : RestrictDuplicatePhoneOnContactTrigger.apxt

RestrictDuplicatePhoneOnContactTrigger.apxt [Apex Trigger]

Create Apex Class Controller →

Step 2:- Create Apex Class : duplicatePhoneOnContactCtrl.apxc

duplicatePhoneOnContactCtrl.apxc [Apex Class Controller]

Final Output → To get source code live demo..

--

--

Easy to learn step-by-step online tutorial by www.w3web.net

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vijayk

Vijayk

Easy to learn step-by-step online tutorial by www.w3web.net