Here we go, today we can see some amazing trigger examples which are mostly used in regular working scenarios and it will fun to know that you can throw errors like validation rules in the apex trigger, you can send an email by apex trigger and so more…
Now Its enough So let’s get started
Five Most used apex trigger scenarios examples
Sending email from apex trigger
Problem: You need to create an apex trigger on contact object which send email when contact will inserted. Trigger code : Check our trigger : Create a new contact record with email address and hit save After your contact will save you receive a mail like this Was this blog is useful?
Throw Error when user tries to delete the contact without account
Problem: You need to create an apex trigger on the contact object which is throwing an error whenever user tries to delete the contact without an account Trigger code : Check the error : Create a contact without selecting a account and hit save Which is look like this Now try to delete that account.…
Opportunity Checkbox isValueCorrect Salesforce Apex Trigger
Problem: Create a custom checkbox field on the opportunity (label: IsValueCorrect)If the stage updated to closed-won only the IsValueCorrect check box is checked Trigger code : Check our trigger : Create a opportunity record and chose stage as qualification and hit save Then update the same record stage as closed Won so ‘Is_value_correct’ check-box will…
Change the beginning of the product code whenever we insert a new product
Problem: You need to create a trigger on the product object which fires every time we insert a new product, we want to make sure that we will add XYZ at the beginning of that product code. Trigger code : Check our trigger : Create a new product and give product code as V305001 and…
Update description in contact object whenever a new contact is created or updated
Problem: You need to create an apex trigger on the contact object which is fire whenever a new contact is created or updated and show the default description accordingly Trigger code : Output : Create a contact and check description is blank or not then hit save When contact is inserted description will be “…
Was this blog is useful?
⭐⭐⭐⭐⭐
Rating: 5 out of 5.Help Others, Please Share
- Click to share on Facebook (Opens in new window)
- Click to share on LinkedIn (Opens in new window)
- Click to share on Telegram (Opens in new window)
- Click to share on Twitter (Opens in new window)
- Click to share on WhatsApp (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Click to email a link to a friend (Opens in new window)
- More