
Can any one help me out with this Errors.I have a trigger on opportunitylineitem and written a test class.When I deploy the trigger I get different Error .Any help very much appreciated. All the test classes are having above 75% code coverage ,but it throws an Error in production environment as :
Code Coverage Failure
Your organization's code coverage is 23%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
editAfterApproval
updatecopyPrice
LockQuotes
CopyTierPrices
updateReadyForReview
update10Kand2k
All have 75% code coverage.
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
BlxOppclonecontrollerTestClass BlxOppClone 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.BlxOppclonecontrollerTestClass.BlxOppClone: line 15, column 1
Oli_multiple_Products_TestClass ValidateOlimultipleproducts 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.Oli_multiple_Products_TestClass.ValidateOlimultipleproducts: line 15, column 1
TestInvoiceController Invoicemethodtest System.AssertException: Assertion Failed: Expected: 1000.00, Actual: 0.02
Stack Trace: Class.TestInvoiceController.Invoicemethodtest: line 105, column 1
TestInvoiceController Invoicemethodtest1 System.AssertException: Assertion Failed: Expected: 1000.00, Actual: 2.00
Stack Trace: Class.TestInvoiceController.Invoicemethodtest1: line 258, column 1
X10Kand2kTest X10Kand2kTest System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: UnitPrice (only one of unit price or total price may be specified): [UnitPrice]
Stack Trace: Class.X10Kand2kTest.X10Kand2kTest: line 54, column 1
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);
}
}
}
TestClass:
@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;
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;
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;
}
}
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.But 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;
previously all the opportunitylineitem had the same variable as oli and i have changed them.
Can we have the hardcode value or id in test class.Any help very much appreciated.Thanks in Advance.