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
nikkeynikkey 

Errors while deploying a trigger to production:CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

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.


 
ManojjenaManojjena
Hi Nikkey,

Try to use 
@isTest (seeAllData=true)  on top od tha class and try to Query from PiceBook and create Product and PriceBookEntry .
Do n't hard code any thing in test calss as the record Id will not match in production it will fail the unit test
Follow below links and let  me know any issue .
http://stackoverflow.com/questions/9164986/how-do-i-avoid-standard-price-not-defined-when-unit-testing-an-opportunitylineit
nikkeynikkey
Hi Manoj Kumar jena ,
Thanks for your reply.I checked the PriceBookEntryId='01ud0000004YWFqAAO' in production and the pricebook object the got openend with  the same details.One of the test class has  (seeAllData=true) ,can we use  (seeAllData=true) for all the test classes.Any help very much appreciated.
ManojjenaManojjena
Hi Nikkey,
We should use seealldata=True in that case where we need to query from existing data set as we can not create data set fro that particular object .
nikkeynikkey
Manoj Kumar jena ,
I need to use for the new trigger test class as seealldata=True
ManojjenaManojjena
Yes you can use where ever you have query from existing record . Replace hard coded Id  and use this and query .