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

Problem with trigger on User object
Hello,
as I am aware, Triggers on the User object are a bit 'hinky' but a customer had a requirement for a trigger.
This is the Trigger I wrote:
trigger userTrigger on User (before insert, before update) { private User[] newUser = Trigger.new; private User[] oldUser = Trigger.old; if(oldUser[0].isActive == false && newUser[0].isActive == true){ newUser[0].Last_Inactive__c = System.now(); } if(oldUser[0].isActive == true && newUser[0].isActive == false){ newUser[0].Last_Active__c = System.now(); } }
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, userTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.userTrigger: line 5, column 1: [] Plasma_Production line 1 Force.com run test failure
What can I do about it? I am currently out of ideas how to get around this error.
Thanks in advance,
hoomel
All Answers
Guys, I am really questioning myself right now. But good that it was such an obvious thing I overlooked!
Thanks for the quick help!