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

System.NullPointerException: Attempt to de-reference a null object - Update value on Contacts with Account Ids
Thank you in advance
I am attempting to pull the Account Ids from a custom object. Once I have the Account Ids I am attempting to pull all the Contacts associated with the Accounts and update a Account_Relationship_Status__c field, but continue to receive the following error: System.NullPointerException: Attempt to de-reference a null object
I have placed System.debug statements in the code in hopes to figure it out, but that has been unsuccessful. Can someone tell me what I seem to be missing?
Log results of the Debug Statements:

Thank you in advance.
I am attempting to pull the Account Ids from a custom object. Once I have the Account Ids I am attempting to pull all the Contacts associated with the Accounts and update a Account_Relationship_Status__c field, but continue to receive the following error: System.NullPointerException: Attempt to de-reference a null object
I have placed System.debug statements in the code in hopes to figure it out, but that has been unsuccessful. Can someone tell me what I seem to be missing?
Public List<Contact> contList; for(Red_Zone__c rzAcct: [SELECT Account__c, status__c, Escalation__c FROM Red_Zone__c WHERE status__c ='Open' and Escalation__c ='Red Zone']){ if (rzAcct.Account__c != Null && rzAcct.status__c != Null && rzAcct.Escalation__c != Null){ System.debug('rzAcct.id '+rzAcct.id); System.debug('rzAcct.Account__c '+rzAcct.Account__c); System.debug('rzAcct.Status__c '+rzAcct.status__c); System.debug('rzAcct.Escalation__c '+rzAcct.Escalation__c); for (Contact con: [SELECT account_relationship_status__c, AccountId FROM Contact WHERE AccountId =:rzAcct.Account__c]){ System.debug('con.id '+con.id); System.debug('con.account_relationship_status__c '+con.account_relationship_status__c); System.debug('con.AccountID '+con.AccountId); con.account_relationship_status__c ='Red Zone'; contList.add(con); } } System.debug('contList '+ contList); Update contList; }
Log results of the Debug Statements:
Thank you in advance.
Let us know if it helps
Thanks for the help, but unfortunately that would not work, because the value in the Contact Object field would have an account_relationship_status__c default value of null until this updates it. The thought is we have an object that references the account called Red_Zone__c that we complete when we are working through issues with the customer. So when we are working through issues we want to update the Contact Object to indicate that the customer is working through issues with us. So by default the account_relationship_status__c field would be null.
Robert
The problem was that I never instaitated the variable contList at the begining, so it did not exist and I was trying to update something that does not exist:
Hope this helps someone