0

I have a trigger that i want to fire when a checkbox is set as true:

The conditions of my If statement are as follows:

c.DetailsConfirmed__c == true && trigger.oldmap.get(c.id).DetailsConfirmed__c == null

This works fine is a record is created and updated to DetailsConfirmed__c =true but if some one sets DetailsConfirmed__c = true when the record is created I get a null reference error.

Is there a way to check and make sure there was an old record first?

1 Answer 1

3

There is no oldmap during an insert trigger.

Your condition should check if the trigger is update before checking the oldmap. Also, your condition must return true if the current value is true and the trigger is insert.

Try the below code:

c.DetailsConfirmed__c == true && ((trigger.isUpdate && trigger.oldmap.get(c.id).DetailsConfirmed__c == null) || trigger.isInsert)
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .