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’);
}
}
}
}