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
rohit.mehtarohit.mehta 

Attempt to de-reference a null object

Hi,

I have a PRM enabled org. I have an afterUpdate trigger on Opportunity. In the code, I am doing this -

Code:
//get the opp fields  
Set<Id> oppIds = new Set<Id>();
for (Opportunity opp : Trigger.new) {
oppIds.add(opp.Id);
}

Map<Id, Opportunity> opportunityMap = new Map<Id, Opportunity>(
[Select Id, partnerAccountId, isClosed, isWon, Partner_Amount__c,
closeDate from Opportunity where Id In :oppIds]);

 Now when I do this

Code:
for (Opportunity o : Trigger.new) {
Opportunity opp = opportunityMap.get(o.Id);

if (opp.partnerAccountId != null) {

It works fine when I do this within Salesforce, but we have a quoting tool - QuoteWerks, which also updates opportunities. This tool throws a Null pointer exception - Attempt to de-reference a null object on this line -
opp.partnerAccountId != null

Any ideas why this would happen.

Thanks,
Rohit
 



Drew1815Drew1815
I think the 'opp' variable is null. Therefore, when you try to get the opp.PartnerAccountId field value, it is throwing the error.
Try adding some System.debug messages to figure out what Opportunities are being added to the Map object and then more debug messages to identify if any Opportunity is being retrieved when you get the Opportunity from the Map.

I hope this helps.

rohit.mehtarohit.mehta
You were right...the opportunity is null

What is surprising is when I retrieve a list it works while Map does not.

Code:
//does not work
Map<Id, Opportunity> opportunityMap = new Map<Id, Opportunity>(
[Select Id, partnerAccountId, isClosed, isWon, Partner_Amount__c, closeDate
from Opportunity where Id In :oppIds]);

//works
List<Opportunity> opportunityList =
[Select Id, partnerAccountId, isClosed, isWon, Partner_Amount__c,
closeDate from Opportunity where Id In :oppIds];

 
Any ideas why?

Thanks,
Rohit