Author name: Himanshu

Share Accounts with Standard Users.

This trigger automatically shares newly created Account records with a user holding the “Standard User” profile, granting them edit permissions. It works seamlessly with private OWD settings. Learn more with this YouTube playlist. Solution: trigger AccountTrigger on Account (after insert) {if(Trigger.isInsert){ if(Trigger.isAfter){               AccountTriggerHandler.shareAccWithStdUser(Trigger.new);            }  […]

Share Accounts with Standard Users. Read More »

Prevent Duplicate Contacts by Email

This trigger ensures no duplicate Contact records are created by checking for existing Contacts with the same email address. Users receive an error if a duplicate is detected. For hands-on practice, visit this YouTube playlist. Solution: public static void preventDuplicateEmail(List<Contact>conList,Map<Contact> oldMap){                Set<String> emailSet= new Set<String>();       

Prevent Duplicate Contacts by Email Read More »

Default Position Fields for New Records

This trigger populates default values for fields like Open Date, Min Pay, and Max Pay when a new Position record is created and marked as a “New Position.” Learn how to write such triggers with this YouTube playlist. Solution: trigger PositionTrigger on Position__c (before insert) {           if(Trigger.isInsert){ if(Trigger.isBefore){     

Default Position Fields for New Records Read More »

Demo Trigger.isExecuting Context Variable

This example showcases the use of the Trigger.isExecuting context variable to determine whether a call is from a trigger context or another source, enabling context-aware logic execution. For detailed examples, explore this YouTube playlist. Solution: public class AccountHandler{ public Boolean        handleAccount(List<Account> accList){             System.debug(‘Trigger is executing :

Demo Trigger.isExecuting Context Variable Read More »

Restrict Case Deletion to System Admins

This trigger restricts the deletion of Case records to users with the System Administrator profile, ensuring that only authorized personnel can perform such actions. Explore more triggers here: YouTube playlist. Solution: public class CaseTriggerHandler {       public static void handleBeforeDelete (List<Case> oldRecords) {             Id currentUserProfileId = UserInfo.getProfileId(); User Info. 

Restrict Case Deletion to System Admins Read More »

Prevent Contact Creation Without Parent Account

This trigger enforces data integrity by preventing the creation of Contact records without a parent Account. Users receive an error message when attempting to save such Contacts. For more trigger examples, visit this YouTube playlist. Solution:public class ContactTriggerHandler {            public static void handleBeforeInsert (List<<Contact> newRecords) {         

Prevent Contact Creation Without Parent Account Read More »

Restrict Account Updates to Private Ownership

This trigger blocks users from saving Account updates if Ownership is set to “Private.” It includes validation logic to ensure data complies with business rules. For further learning, explore this YouTube playlist. Solution: public class Account TriggerHandler {      public static void handleBeforeUpdateActivities (List<Account> newRecords, Map<Id,Account> oldMap) {           for (Account

Restrict Account Updates to Private Ownership Read More »

Prevent Duplicate Contact Creation by Email

This trigger ensures that Contact records with duplicate Email, Last Name, and Phone values are not created. It validates existing records and throws an error if duplicates are found. For hands-on practice, check this YouTube playlist. Solution: public class ContactTriggerHandler {                public static void handleBeforeInsert (List<Contact> newRecords) { 

Prevent Duplicate Contact Creation by Email Read More »

Update Opportunity Amount Based on Stage Change

This trigger calculates and updates the Opportunity Amount when the Stage changes. The amount is derived from the Probability and Expected Revenue, ensuring accurate financial projections. Learn more about triggers from this YouTube playlist. Solution: public class OpportunityTriggerHandler {       public static void handleActivitiesBeforeUpdate (List<Opportunity> newRecords, Map<Id, Opportunity> oldMap) { //figure out if

Update Opportunity Amount Based on Stage Change Read More »

Restrict Lead Deletion in Progress

This trigger prevents users from deleting Leads with a Status of “Working-Contacted,” ensuring that active leads are not accidentally removed. Practice similar scenarios using this YouTube playlist. Solution:public class LeadTriggerHandler {public static void handleActivitiesBeforeDelete (List<Task> leadRecords) {                    for (Lead leadRec : leadRecords) {       

Restrict Lead Deletion in Progress 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 :)