You need to sign in to do that
Don't have an account?
Rajesh Meti
Null Pointer exception when retrieving PriceBookEntryId from OpportunityLineItem on before update event
Hi,
I am getting null pointer exception while retrieving PricebookEntry value from OpportunityLineItem and code details are below:
I am getting error for the venet if(Trigger.isBefore && Trigger.isUpdate) and it was working fine eralier sudeenly satrted throwing error today:
Trigger:
Apex Class:
Can any one please help me to overcome this error.
Regards,
Rajesh Meti
I am getting null pointer exception while retrieving PricebookEntry value from OpportunityLineItem and code details are below:
I am getting error for the venet if(Trigger.isBefore && Trigger.isUpdate) and it was working fine eralier sudeenly satrted throwing error today:
Trigger:
trigger OpportunityLineItemTriggers on OpportunityLineItem (after insert, after update, after delete ,before insert, before update ) { OLIClass OLineItemClass = new OLIClass(); if(Trigger.isBefore && Trigger.isInsert) { OLIClass.updateOppLineItem_Field(Trigger.New); } if(Trigger.isBefore && Trigger.isUpdate) { OLIClass.updateOppLineItem_Field(Trigger.New); } }
Apex Class:
public without sharing class OLIClass { // Function to copy Offer Field Value from Product to OpportunityLineItem P public void updateOppLineItem_Field(List<OpportunityLineItem> newList) { Set<Id> PBEIds = new Set<Id>(); for(OpportunityLineItem oli: newList) { PBEIds.add(oli.PricebookEntryId); } Map<ID,PricebookEntry> pbeMap = new Map<ID,PriceBookEntry>([Select p.Product2.Offer__c, p.Product2Id, p.Id From PricebookEntry p where ID IN : PBEIds]); for(OpportunityLineItem oli: newList) { oli.Offer__c = map_PBE.get(oli.PricebookEntryId).Product2.Offer__c; } } }
Can any one please help me to overcome this error.
Regards,
Rajesh Meti
If it's the above line, it's likely that either your map_PBE map is null (I see a pbeMap, but no map_PBE, so curious to how that compiles), or your Opportunity Line Item doesn't have any pricebookentryid associated with it.
Sorry its pbeMap and corrected class is below and this is working code suddenly its started throwing exception today for event if(Trigger.isBefore && Trigger.isUpdate) but the same works fine for event if(Trigger.isBefore && Trigger.isInsert).
Apex Class:
Regards,
Rajesh Meti
to
for(OpportunityLineItem oli: [Select Id, Offer__c,PricebookEntryId from OpportunityLineItem Where Id in :newList])
I wanted to know why it is not working for previous where it use to work earlier??
Can any one pknow why it is that for before Update event??
Thanks & Regards,
Rajesh Meti
I have not done any changes to system almost from last 1 month. I was working with same code yesterday but suddenly today :-)
I have debugged as per your suggestion and result is bleow:
System.debug('Is PBE ID the same?' + Trigger.oldMap(oli.Id).PricebookEntryId == oli.PriceBookEntryId);
FATAL_ERROR|System.StringException: Invalid id: Is PBE ID the same?01uK00000045RxxIAE
System.debug('Is PBE ID the same?' + Trigger.oldMap(oli.Id).PricebookEntryId +'=='+ oli.PriceBookEntryId);
16:41:38.982 (982606495)|USER_DEBUG|[45]|DEBUG|Is PBE ID the same?01uK00000045RxxIAE==null
Thanks & Regards,
Rajesh Meti
Since Winter 15 was developed (this monday) in sandbox we have the following error in SF internal code, but not our code. We will explain you an example.
We have a controller class with pricebookentryid in an opportunitylineitem update. We triggered the update in opportunitylineitem with a value in pricebookentryid.
Then, opportunitylineitem before update trigger started without pricebookentryid (=null).
We have found out that when the code executes a line with an update on an opportunity line item in a controller class, right before the OpportunityLineItem Before Update trigger gets executed, the pricebookEntry value gets lost (it becomes null). That doesn't happen with other OpportunityLineItem fields nor any other objects.
We have not got this problem before and now in production there is not any problem about it. We haven't change the code. There is the same code in sandbox an production. The code was deployed to production and it works. This only happens in sandbox.
https://success.salesforce.com/issues_view?id=a1p30000000T5c9AAC