You need to sign in to do that
Don't have an account?
Sabrent
Strange - Attempt to dereference null object error
I have a strange thing happening here.
I have this working otherwise, however for one condition -
Whenever the Account_Division__c is null (i.e not entered in the system), this logic fails to even enter the Else loop thus giving me the Attempt to dereference a null object error.
Any ideas why ??
List <Employee__C> empList = [SELECT ..........]; for(Employee__c emp : empList){ system.debug('Check the vlaue of Branch Email: ' +emp.Branch__r.Branch_Email__c); system.debug('Check the Kelly Division: ' +emp.Account_Division__c); if(emp.Account_Division__c.contains('DAO')) { emp.Email_Branch__c = CT_EmailFields__c.getInstance().Mailbox__c; } else if(!emp.Account_Division__c.contains('DAO') || emp.Account_Division__c==null){ emp.Email_Branch__c = emp.Branch__r.Branch_Email__c; } }
It's because you're not doing a null check until the else if... and even then it's in the wrong order. Try this:
All Answers
It's because you're not doing a null check until the else if... and even then it's in the wrong order. Try this:
Just check first if the emp.Account_Division__c is diffrent from null.
Cheers
Hi Rov,
It looks like you want to assign Email_Branch__c field value with emp.Branch__r.Branch_Email__c, if the Account Division is null. If it is the case, then try the following code:
If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.
Thanks for al lyou r responses . Much appreciated, .