• Amit Ray
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
After entering credentials and security token for force.com IDE, eclipse doesn't go to the next screen or connect to sandbox.  Has anyone experienced this before? I tried selecting other in the dropdown to specify the end point. Still same behavior. Please help, I have been stuck with this error for a day now.
Create a method for inserting accounts.

To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.

The Apex class must be called AccountHandler and be in the public scope
The Apex class must have a public static method called insertNewAccount
The method must accept an incoming string as a parameter, which will be used to create the Account name
The method must insert the account into the system and then return the record
The method must also accept an empty string, catch the failed DML and then return null
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

 
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) {
		
	
	}

}