All the test classes are on opportunitylineitem. I tried testing each test classes all are running with code coverage more than 75% in sandbox as well as production. When I try to migrate the newly written trigger its throwing Error . When I checked the test classes, I could see the lines are opportunitylineitem.
At AccOppsegmentTestClass :The Error line is insert olii and in the test class it is declared as
OpportunityLineItem olii = new OpportunityLineItem (Quantity=2, OpportunityId=opp.Id, TotalPrice=10, PriceBookEntryId='01ud0000004YWFqAAO');
insert olii;
At BlxOppclonecontrollerTestClass :The Error line is insert olli and in the test class it is declared as
OpportunityLineItem olli = new OpportunityLineItem (Quantity=2, OpportunityId=opp1.Id, TotalPrice=10, PriceBookEntryId='01ud0000004YWFqAAO');
insert olli;
At Oli_multiple_Products_TestClass :The Error line is insert ooli and in the test class it is declared as
OpportunityLineItem ooli = new OpportunityLineItem (Quantity=2, OpportunityId=opp.Id, TotalPrice=10, PriceBookEntryId='01ud0000004YWFqAAO');
insert ooli;
Error as :
AccOppsegmentTestClass validateAccOppsegment System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Populate_Extension: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Populate_Extension: line 15, column 1: []
Stack Trace: Class.AccOppsegmentTestClass.validateAccOppsegment: line 19, column 1
Similarly for other test class i do get the same error.Any help very much appreciated
Trigger :
trigger Populate_Extension on OpportunityLineItem (Before Insert) {
//List<OpportunityLineItem> oli= new List<OpportunityLineItem>();
Set<Id> pbeIds = new Set<Id>();
for (OpportunityLineItem opli : Trigger.new) {
pbeIds.add(opli.PricebookEntryId);
}
Map<Id, PricebookEntry> pbeMap = new Map<Id, PricebookEntry>([select Id, Product2.Product_Line__c from PricebookEntry where Id in :pbeIds]);
for(OpportunityLineItem opli:Trigger.new){
if(pbeMap.get(opli.PricebookEntryId).Product2.Product_Line__c == 'DIE'){
system.debug('PricebookEntry.Product2.ProductLine!!!!!!!!!'+opli.PricebookEntry.Product2.Product_Line__c);
opli.UnitPrice=0.01;
system.debug('Unitprice%%%%%%%%%%%%'+opli.UnitPrice);
opli.Newextension__c=opli.Quantity*0.01;
system.debug('Newextension@@@@@@@@@@@'+opli.Newextension__c);
}
else {
opli.UnitPrice=1;
system.debug('Unitprice^^^^^^^^^^^^^^'+opli.UnitPrice);
opli.Newextension__c=opli.Quantity*1;
system.debug('Newextension$$$$$$$$$$$'+opli.Newextension__c);
}
}
}
Test class :
@istest
public class Populate_ExtensionTestclass{
static testmethod void PopulateExtensiontest(){
Date closeDt = Date.Today();
date myDate = date.today();
Account a2 = new Account(Name ='icrm testing acc');
insert a2;
opportunity oppr = new opportunity(Name='testing DIE 4/6/2015' , AccountId= a2.Id,StageName = 'Prospecting',
CloseDate = closeDt);
insert oppr;
Pricebook2 pb22 = new Pricebook2(Name='testDIE');
insert pb22;
Product2 pro2 = new Product2(Product_Line__c='DIE',Name='BXCD',Product_Code_Item_Number__c='BXCD24', isActive=true);
insert pro2;
PricebookEntry pbe2 =new PricebookEntry(unitprice=0.01,Product2Id=pro2.Id,Pricebook2Id=Test.getStandardPricebookId(),
isActive=true,UseStandardPrice = false);
insert pbe2;
OpportunityLineItem OPplineitem2 = new OpportunityLineItem (Quantity=2, OpportunityId=oppr.Id,UnitPrice=0.01,PriceBookEntryId=pbe2.Id,
Newextension__c=0.02,Bin_Item_Code__c='BXCD2424');
insert OPplineitem2;
}
static testmethod void PopulateExtensiontest1(){
Date closeDt = Date.Today();
date myDate = date.today();
Account a2 = new Account(Name ='Non icrm testing acc');
insert a2;
opportunity oppr = new opportunity(Name='testing NONDIE 4/6/2015' , AccountId= a2.Id,StageName = 'Prospecting',
CloseDate = closeDt);
insert oppr;
Pricebook2 pb22 = new Pricebook2(Name='testNonDIE');
insert pb22;
Product2 pro2 = new Product2(Product_Line__c='NONDIE',Name='BXCDXXX',Product_Code_Item_Number__c='BXCD2424', isActive=true);
insert pro2;
PricebookEntry pbe2 =new PricebookEntry(unitprice=1,Product2Id=pro2.Id,Pricebook2Id=Test.getStandardPricebookId(),
isActive=true,UseStandardPrice = false);
insert pbe2;
OpportunityLineItem OPplineitem2 = new OpportunityLineItem (Quantity=25, OpportunityId=oppr.Id,UnitPrice=1,PriceBookEntryId=pbe2.Id,
Newextension__c=25);
insert OPplineitem2;
}
}