function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kshannonkshannon 

NullPointerException: Attempt to de-reference a null object Adding AccountId to List<Id>

16:5:11.693|METHOD_ENTRY|[10,9]|LIST:Id.add(Id)
16:5:11.693|EXCEPTION_THROWN|[10,9]|System.NullPointerException: Attempt to de-reference a null object
16:5:11.693|METHOD_EXIT|[10,9]|add(ANY)
16:5:11.693|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

 

is the system log...

 

the code is:

 

 

trigger LapsedFunderToFunder on Opportunity (after insert) {


List<Id> effectedAccounts;

for(Opportunity o : Trigger.new){

system.debug('accountid - ' + o.AccountId);

effectedAccounts.add(o.AccountId);

 Not sure why an Id won't add to the List<Id>... strange.. There must be something I'm missing.

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
The NPE is because effectedAccounts is null, you never assigned it to anything.

All Answers

SuperfellSuperfell
The NPE is because effectedAccounts is null, you never assigned it to anything.
This was selected as the best answer
kshannonkshannon
Silly typo! Thanks...  kept digging further and further and missed the obvious!