• Rajesh Meti
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
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:
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
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:
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
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:
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