Author name: Himanshu

Track Present Employee Count on Events

This trigger updates the “Present Employee Count” on the related Account whenever Employee records are inserted, deleted, or undeleted. Explore related triggers here: YouTube playlist. Solution: //Same code will work for insert, delete and undelete trigger EmployeeTriggeron Employee__c(after insert,after delete,after undelete) { if(Trigger.isInsert){ if(Trigger.isAfter){                        […]

Track Present Employee Count on Events Read More »

Adjust Left Employee Count on Undelete

When an Employee record is undeleted, this trigger decreases the “Left Employee Count” on the related Account, maintaining accurate employee metrics. Learn more with this YouTube playlist. Solution: trigger EmployeeTrigger on Employee__c (After undelete) {        if(Trigger.isUnDelete){                   if(Trigger.isAfter){        EmployeeTriggerHandler.updateLeftEmpCountUndeletedOnes(Trigger.New);       

Adjust Left Employee Count on Undelete Read More »

Send Welcome Email on Contact Creation

When a new Contact is created, this trigger sends a welcome email to the email address provided, using a specified email template. For similar examples, visit this YouTube playlist. Solution: trigger ContactTrigger on Contact (after insert)      {   if(Trigger.isInsert){ if(Trigger.isAfter){              ContactTriggerHandler.sendEmailToContact(Trigger.new);       }   }}public class ContactTriggerHandler{ public

Send Welcome Email on Contact Creation Read More »

Roll Up Opportunity Amount to Account

This trigger calculates the total Opportunity Amount for all related Opportunities and updates the Account’s Annual Revenue field whenever an Opportunity is created, updated, or deleted. Explore more examples via this YouTube playlist. Solution://Call this method for insert, update, delete and undelete event public static void populateAmountOnAccount(List<Opportunity>           oppList,Map<Id,,Opportunity> oldMap){ Set<Id> accIds

Roll Up Opportunity Amount to Account Read More »

Create Task for Lead Owner on Lead Creation

This trigger generates a follow-up Task for the Lead Owner when a new Lead record is created. It ensures timely engagement with prospects and automates task assignments. Explore similar examples in this YouTube playlist. Solution: public class LeadTriggerHandler {      public static void handleActivitiesAfterInsert (List<Lead> leadRecords) {            List<Task> taskListToInsert

Create Task for Lead Owner on Lead Creation Read More »

Create Task for Opportunity Owner on Stage Change

This trigger creates a Task for the Opportunity Owner to split revenue when an Opportunity’s Stage is updated to “Closed Won.” It facilitates post-sales follow-up and streamlines task assignment. Practice similar triggers via this YouTube playlist. Solution: public class OpportunityTriggerHandler {       public static void handleActivitiesAfterInsert () {}       public static

Create Task for Opportunity Owner on Stage Change Read More »

Handle Recursion in Opportunity Stage Updates

This trigger updates the Opportunity Description based on its Stage while preventing recursive updates, ensuring data consistency without infinite loops. Learn more about triggers here: YouTube playlist. Solution: public class preventRecursion { public           static Boolean firstCall=false;}trigger OpportunityTrigger on Opportunity(after                 update){ if(Trigger.isUpdate){ if(Trigger.isAfter){     

Handle Recursion in Opportunity Stage Updates Read More »

Validate Opportunity Creation with Database Methods

This example demonstrates using Database methods and addError() in triggers to validate Opportunities during insertion and handle errors gracefully. For further learning, check this YouTube playlist. Solution: trigger AccountTrigger on Account (after insert) {if(Trigger.isInsert){ if(Trigger.isAfter){                              AccountTriggerHandler.createOpp(Trigger.new);           

Validate Opportunity Creation with Database Methods 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 :)