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){
                                                                         OpportunityTriggerHandler.validateAmount(Trigger.New);
                       }
             }
}
public class OpportunityTriggerHandler {

          public static void validateAmount(List oppList){ for(Opportunity
                      opp:oppList){ if(opp.Amount == null){ opp.addError(‘Amount field can not be
null’);
                                 }
                       }
         }
}

Want to Apply As Content Writer?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

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