You need to sign in to do that
Don't have an account?
AlecS
Opportunity Trigger to Check Old Values
I have an Opportunity trigger. The trigger checks for the old value of the opportunity, specially the StageName=ClosedWon.
However, if I click on "New" opportunity and ClosedWon the opportunity the first time itself, the checking fails, because there's no old value at all for such opportunity.
How do I catch and fix this?
Thanks!
Alec,
I think your Trigger is firing on both insert and update event.As insert event does not have Trigger.old values,it is throwing you an error.
Please change it to run only on update events.Change it from :-
trigger <TriggerName> on Opportunity(before insert,before update){
// your code
}
to
trigger <TriggerName> on Opportunity(before update){
// your code
}
Salesforce provides you two trigger variables.
Trigger.isInsert and Trigger.isUpdate
You can differentiate when to check for the old value using them.
Example:
if(Trigger.isInsert){
// your logic
}
else if(Trigger.isUpdate){
// check for the condition first and then execute your logic.
}