1

Can any one help me with this Error ,Im facing with these three diffent types of Error.

In DC it shows 80% overall coverage in sandbox when we move in to production it say it has only 71% overall coverage

1)Code Coverage Failure
Your organization's code coverage is 71%. You need at least 75% coverage to complete this deployment.

   2) Details: Average test coverage across all Apex Classes and Triggers is 71%, at least 75% test coverage is required.

3)TestInvoiceController.Invoicemethodtest(), Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is inactive): [PricebookEntryId] Class.TestInvoiceController.Invoicemethodtest: line 25, column 1

When i test the For Invoice Controller , the code coverage is NONE.

Code :

    @istest
Public class  TestInvoiceController{

 static Testmethod void Invoicemethodtest(){

 Date closeDt = Date.Today();

//list<opportunity> opp = new list<opportunity>();

Account a = new Account();
a.Name = 'icrm test acc';

insert a;

opportunity op = new opportunity(Name='test DIE 4/6/2015' ,  AccountId= a.Id,StageName = 'Prospecting', 
                                   CloseDate = closeDt, Shipment_Info__c='test',
                                   Shipping_Address_Line1__c='Road No 37',
                                   Shipping_Address_Line2__c='Jubilee Hills',
                                   Shipping_Address_Line3__c='Land Mark Neerus',
                                   Shipping_City__c='Hyd',
                                   Shipping_State_Province__c='TS',
                                   Shipping_Zipcode__c='500081',
                                   Shipping_Country__c ='India',
                                   Bill_of_Lading__c='This is waybill1 this is waybill 2 waybill3 -34958309458 waybill - 44570375');

  insert op;

// list<opportunitylineitem> ol = new list<opportunitylineitem>(); 

 OpportunityLineItem OPplineitem= new OpportunityLineItem (Quantity=2, OpportunityId=op.Id,UnitPrice=0.01, PriceBookEntryId='01ud0000004aJb5AAE');

  insert OPplineitem;
  }

 static Testmethod void Invoicemethodtest1(){

 Date closeDt = Date.Today();

  //list<opportunity> opp = new list<opportunity>();
  Account a = new Account();
a.Name = 'icrm test acc';

insert a;

opportunity op = new opportunity(Name='test NonDIE 4/6/2015' , AccountId= a.Id,StageName = 'Prospecting', 
                                   CloseDate = closeDt,Shipment_Info__c='test',
                                   Shipping_Address_Line1__c='Road No 37',
                                   Shipping_Address_Line2__c='Jubilee Hills',
                                   Shipping_Address_Line3__c='Land Mark Neerus',
                                   Shipping_City__c='Hyd',
                                   Shipping_State_Province__c='TS',
                                   Shipping_Zipcode__c='500081',
                                   Shipping_Country__c ='India' , 
                                   Bill_of_Lading__c='This is waybill1 this is waybill 2 waybill3 -34958309458 waybill - 44570375');

  insert op;

 //list<opportunitylineitem> ol = new list<opportunitylineitem>(); 

 OpportunityLineItem OPplineitem= new OpportunityLineItem (Quantity=2, OpportunityId=op.Id,UnitPrice=1, PriceBookEntryId='01ud0000005PvrBAAS');

  insert OPplineitem;

     }                        
  }

IS the test class correct or any blunt mistakes.Any help very much appreciated.

2 Answers 2

1

In your test, in the line before your insert where you are creating a new OpportunityLineItem, you have PriceBookEntryId='01ud0000004aJb5AAE'. IDs aren't preserved from sandbox to production and generally hardcoding IDs explicitly in code is discouraged. This is causing your test to fail and reflect 0% coverage.

3
  • :IF i dont give any value for PriceBookEntryId the testmethods fails ,if i hard code with the value ,the test method get pass but shows 0% coverage.If i remove the PriceBookEntryId field ,again it throws an error.Any help very much appreciated.
    – nikkey
    Apr 10, 2015 at 19:21
  • Your test is not succeeding, it is throwing an error. You need to create a product, then a pricebookentry in the standard pricebook, then create your opportunity line.
    – CyberJus
    Apr 10, 2015 at 20:34
  • 1
    Set a variable for your price book Id and query based on name of Pricebook PricebookEntryId pbe = [SELECT Id from PricebookEntryId WHERE Name ="your pbename"]; Apr 10, 2015 at 20:46
0

I would've left this as a comment, but my points prevent me from commenting. Couldn't you use a query to get the Id without hardcoding...something like

Select Id FROM PriceBookEntry WHERE Name=(the name of the PriceBookEntry)?

Also, on the page where the errors are scroll down and look to see if other apex classes failed. Sometimes your code can cause another class to fail because you aren't referencing something that is required elsewhere. For instance, one time that happened to me because there was a field that was required because of a validation rule and it wasn't in my test so the record couldn't validate which caused the failure. The errors at the bottom are usually more helpful.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .