trigger to prevent delete related record based on lookup relation in salesforce -- w3web.net

Trigger on custom object to prevent delete the related list record based on lookup relation whenever trying to delete parent record, throw an error message using apex class handler trigger in Salesforce | How to prevent delete if parent object has child in Salesforce

Hey guys, today in this post we are going to learn about How to write a Trigger on custom object to prevent delete the related list record based on lookup relation whenever trying to delete parent record, display error message using apex class handler trigger in Salesforce

Real time scenarios:- Write a trigger to prevent delete the related list record. Whenever trying to delete parent record, trigger should be throw an error.

Files we used in this post example

scoreCardTrigger.apxt Apex Class Trigger It will be fired whenever trying to delete related list record.
scoreCardTriggerHandler.apxc Apex Class Controller Apex handler trigger to prevent delete the related list record whenever trying to delete parent record.
Custom Object:- scoreCard__c
Custom Fields:- scoreCardLookup__c (Lookup Relation)

Trigger to prevent delete the related list record based on lookup relation.

Final Output

trigger to prevent delete related record in salesforce -- w3web.net

Other related post that would you like to learn.

  • Find the below steps for this post.

Create Apex Trigger

Step 1:- Apex Class Trigger : scoreCardTrigger.apxt

From Developer Console ➡ File ➡ New ➡ Apex Trigger

contactTriggerRollSummary.apxt [Apex Class Trigger]

Create Apex Class Trigger Handler Controller

Step 2:- Create Apex Class : scoreCardTriggerHandler.apxc

From Developer Console ➡ File ➡ New ➡ Apex Class

scoreCardTriggerHandler.apxc [Apex Class Controller]

trigger to prevent delete related record in salesforce -- w3web.net

Further post that would you like to learn in LWC

To Find Some Important Additional Information
If you think you and your family members also like to earn money in additional time, then go this link. In this site, you can earn money for the lifetime at low effort. To Earn Unlimited Everyday With This Trick, Sign Up Free and Get Magic.. Get Started for Free

Check Out Youtube:- Earn Unlimited Everyday With This Trick:- Click Here

Related Topics | You May Also Like

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.

2 thoughts on “Trigger on custom object to prevent delete the related list record based on lookup relation whenever trying to delete parent record, throw an error message using apex class handler trigger in Salesforce | How to prevent delete if parent object has child in Salesforce”

Leave a Comment