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
Hey guys, today in this post we are going to learn about how to prevent the user to create duplicate Contact based on Phone if Phone number is already exist on related account in Salesforce Apex Trigger.
Apex can be invoked by using triggers. Apex triggers enable you to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions.
There are two types of triggers:-
- 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.
Triggers can also modify other records of the same type as the records that initially fired the trigger. To know more about apex trigger, Click Here →
Final Output → To get source code live demo..
Other related post that would you like to learn in LWC
Create Apex Trigger →
Step 1:- Create Apex Trigger : RestrictDuplicatePhoneOnContactTrigger.apxt
From Developer Console >> File >> New >> Apex Trigger
RestrictDuplicatePhoneOnContactTrigger.apxt [Apex Trigger]
Create Apex Class Controller →
Step 2:- Create Apex Class : duplicatePhoneOnContactCtrl.apxc
From Developer Console >> File >> New >> Apex Class
duplicatePhoneOnContactCtrl.apxc [Apex Class Controller]
Further post that would you like to learn in LWC FAQ (Frequently Asked Questions)
Final Output → To get source code live demo..
Hi, This is Vijay behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net
Originally published at https://www.w3web.net on May 23, 2022.