You need to sign in to do that
Don't have an account?

Trigger.newMap is null in before insert?
Hi all,
I was happily humming along writing my Case before insert trigger, but when I wrote my tests, they all failed. This appears to be due to the fact that Trigger.newMap is coming up null, and I'm trying to use it late in my trigger. Meanwhile, Trigger.new works just fine.
I added this code to the very beginning of my trigger:
trigger CaseAutocreateContact on Case (before insert) {
System.debug(Trigger.newMap == null?'Trigger.newMap is null!':'Trigger.newMap is populated.');
And lo and behold when I run my tests I see:
20081107011750.678:Trigger.CaseAutocreateContact: line 2, column 5: Trigger.newMap is null!
What gives here? How can Trigger.new be populated but Trigger.newMap be null? My trigger is using the 14.0 endpoint.
Thanks.
I was happily humming along writing my Case before insert trigger, but when I wrote my tests, they all failed. This appears to be due to the fact that Trigger.newMap is coming up null, and I'm trying to use it late in my trigger. Meanwhile, Trigger.new works just fine.
I added this code to the very beginning of my trigger:
trigger CaseAutocreateContact on Case (before insert) {
System.debug(Trigger.newMap == null?'Trigger.newMap is null!':'Trigger.newMap is populated.');
And lo and behold when I run my tests I see:
20081107011750.678:Trigger.CaseAutocreateContact: line 2, column 5: Trigger.newMap is null!
What gives here? How can Trigger.new be populated but Trigger.newMap be null? My trigger is using the 14.0 endpoint.
Thanks.
Note that newMap is only available in before update, after insert, and after update triggers.
for more clarification
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm
Workaround to have something equal to trigger.newMap available:
Why should this workaround work? The records shouldn't have any ids assigned in before insert correct? Isn't that why newMap isn't available in before triggers.