You need to sign in to do that
Don't have an account?
HNT_Neo
Help Understanding Apex Class
Hi Everyone,
I need help in making sense of this Apex class that was created years ago in our org.
Today we ran into an Apex script unhandled exception
Failed to process batch for class 'VolumeMarketBatch'
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.VolumeMarketBatch.execute: line 36, column 1
line 36 below is:
a.Volume_Market__c = pc.Volume_Market__c;
Any help is greatly appreciated.
Thank you
I need help in making sense of this Apex class that was created years ago in our org.
Today we ran into an Apex script unhandled exception
Failed to process batch for class 'VolumeMarketBatch'
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.VolumeMarketBatch.execute: line 36, column 1
line 36 below is:
a.Volume_Market__c = pc.Volume_Market__c;
Any help is greatly appreciated.
Thank you
global with sharing class VolumeMarketBatch implements Database.batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext info) { // Go through and get the list of volume market that has changed String returnQuery = 'select Id, Remodeler_Account__c, Postal_Code__c ' + ' from Zip_Assignment__c ' + ' where Postal_Code__r.Volume_Market_Update__c = true'; return Database.getQueryLocator(returnQuery); } global void execute(Database.BatchableContext info, List<sObject> sobjectList) { // Gets the account and postal codes that have changed List<Id> accountIdList = new List<Id>(); List<Id> pcIdList = new List<Id>(); for (sObject obj : sobjectList) { Zip_Assignment__c zipAssign = (Zip_Assignment__c) obj; accountIdList.add(zipAssign.Remodeler_Account__c); pcIdList.add(zipAssign.Postal_Code__c); } // Goes through the accounts and postal codes that have changed and sets the Volume Market field on the account Map<Id, Account> accountList = new Map<Id, Account>([select Id, Volume_Market__c from Account where Id = : accountIdList]); Map<Id, Postal_Code__c> pcList = new Map<Id, Postal_Code__c>([select Id, Volume_Market_Update__c, Volume_Market__c from Postal_Code__c where Id = : pcIdList]); for (sObject obj : sobjectList) { Zip_Assignment__c zipAssign = (Zip_Assignment__c) obj; Account a = accountList.get(zipAssign.Remodeler_Account__c); Postal_Code__c pc = pcList.get(zipAssign.Postal_Code__c); //System.Debug(pc.Volume_Market__c + a.Volume_Market__c); if (pc != null) { if (pc.Volume_Market__c != null) { a.Volume_Market__c = pc.Volume_Market__c; } pc.Volume_Market_Update__c = false; } } // updates both account and postal codes upsert accountList.values(); upsert pcList.values(); } global void finish(Database.BatchableContext info) { } }
if (zipAssign.Remodeler_Account__c != null && zipAssign.Postal_Code__c != null)
All Answers
You should test if zipAssign.Remodeler_Account__c != null (perhaps)
for (sObject obj : sobjectList) {
Zip_Assignment__c zipAssign = (Zip_Assignment__c) obj;
if (zipAssign.Remodeler_Account__c != null) {
accountIdList.add(zipAssign.Remodeler_Account__c);
pcIdList.add(zipAssign.Postal_Code__c);
}
}
Map<Id, Account> accountList = new Map<Id, Account>([select Id, Volume_Market__c fromAccount where Id = : accountIdList]);
Account a = accountList.get(zipAssign.Remodeler_Account__c);
if (zipAssign.Remodeler_Account__c != null && zipAssign.Postal_Code__c != null)
I am grateful for your help!
It is now good to go!
Was wondering if you use something else than Developer Console to help with coding with Apex?
Check this out.
Same Issue, but different location of the code.
If you have time, can you please check this out:
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000g7IV#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=9062I000000g7LyQAI