Author name: Himanshu

Update Opportunity Stage for Inactive Accounts

This trigger checks if an Account’s “Active” field is updated from “Yes” to “No.” It updates all related Opportunities to “Closed Lost” if their Stage is not already “Closed Won.” For more practice, explore this YouTube playlist. Solution: trigger AccountTrigger on Account (after update) {          if(Trigger.isUpdate){ if(Trigger.isAfter){          […]

Update Opportunity Stage for Inactive Accounts Read More »

Enforce Closed Lost Reason for Opportunities

When an Opportunity is marked as “Closed Lost,” this trigger ensures that the “Closed Lost Reason” field is populated. If it is empty, an error is displayed to the user. Learn more from this YouTube playlist. Solution: trigger OpportunityTrigger on Opportunity (before update) {        if(Trigger.isUpdate){ if(Trigger.isBefore){             

Enforce Closed Lost Reason for Opportunities Read More »

Validate Opportunity Amount During Creation

This trigger validates the Opportunity “Amount” field during creation. If the field is null, the user is prompted with an error, ensuring all Opportunities have valid amounts. Practice triggers like this here: YouTube playlist. Solution: trigger OpportunityTrigger on Opportunity (before insert)            { if(Trigger.isInsert){ if(Trigger.isBefore){             

Validate Opportunity Amount During Creation Read More »

Restrict Opportunity Deletion Based on Stage

This trigger restricts Opportunity deletion if the Stage is “Closed Won” or “Closed Lost.” Only System Administrators can delete such Opportunities. For additional learning, check this YouTube playlist. Solution: trigger OpportunityTrigger on Opportunity (before delete) {        if(Trigger.isDelete){ if(Trigger.isBefore){                             

Restrict Opportunity Deletion Based on Stage Read More »

Allow Account Deletion Only for System Admins

This trigger ensures that only users with the System Administrator profile can delete Account records, adding a layer of security to critical data. Explore more examples here: YouTube playlist. Solution: trigger AccountTrigger on Account (before delete)             { if(Trigger.isDelete){ if(Trigger.isBefore){                       

Allow Account Deletion Only for System Admins Read More »

Block Account Deletion with Related Opportunities

This trigger prevents deletion of an Account if it has any related Opportunities, ensuring no critical relationships are accidentally removed. Practice similar use cases with this YouTube playlist. Solution: trigger AccountTrigger on Account (before delete) {          if(Trigger.isDelete){ if(Trigger.isBefore){                           

Block Account Deletion with Related Opportunities Read More »

Update Left Employee Count on Deletion

When an Employee record is deleted, this trigger updates the “Left Employee Count” field on the related Account, keeping employee metrics accurate. Explore similar triggers here: YouTube playlist. Solution: trigger EmployeeTrigger on Employee__c (After delete)      { if(Trigger.isDelete){ if(Trigger.isAfter){                               

Update Left Employee Count on Deletion Read More »

Undelete Employee and Set Active Status

This trigger ensures that when an Employee record is undeleted, the “Active” field is automatically set to “True,” restoring the record’s operational status. For more hands-on examples, check this YouTube playlist. Solution: trigger EmployeeTrigger on Employee__c (After undelete)             { if(Trigger.isUnDelete){ if(Trigger.isAfter){                   

Undelete Employee and Set Active Status Read More »

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

Fill in this form and we will get in touch with you :)