0

As of now test class code coverage 85%, but when we are validating the chageset getting 0% code coverage error saying `

STANDARD_PRICE_NOT_DEFINED No standard price defined for this product.

Please check my below test class and help us to avoid this error.

@isTest(SeeallData=false)
private class BatchOpportunityInstallbaseTest {

    static testMethod void ValidateOpportunityInstallbase() {

          Installed_Base_Details__c obj = new Installed_Base_Details__c();
          obj.Name='test';
          obj.Product_Family__c ='Automation';
          obj.Product_Line__c ='COML IPC';
          obj.IB_Product_Family__c ='test';
          obj.IB_Product_Line__c ='test';
          obj.IB_Product_Module__c='test';
          insert obj;       

          Oppty_Business_Area_Of_IB_Creation__c obj1 = new Oppty_Business_Area_Of_IB_Creation__c(Name='DCS');
          insert obj1;

          GEOSPOpptyDefaults__c obj2 = new GEOSPOpptyDefaults__c(name='test',APMFamily__c='Test',AUTOFamily__c='test',BMSFamily__c='test',APMProduct__c='test',AUTOProduct__c='test',BMSProduct__c='test');
          insert obj2;
          Test.startTest();
          Account acc = new Account();
          acc.Name='TestAcc';
          acc.salesAreaList__c = '';
          acc.BillingCountry = 'SLOVAKIA';
          acc.BillingCity = 'test city';
          acc.BillingStreet = 'test street';
          acc.ShippingCountry = 'SLOVAKIA';
          acc.CSN__c='CSN1234';
          acc.GEMDM_Customer_Connect_Request_Status__c ='Approved';
          insert acc;

          Id devRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('GEAC Flow Oppty').getRecordTypeId();
          Opportunity opp =new Opportunity();
          opp.AccountId = acc.id;
        // Changed the Opportunity stage value from AC5-Closed Won to Closed - Booked by Sagar on 24 Feb 2017 for US-03283  
          opp.StageName='Closed - Booked';
          opp.name='test Opp';
          opp.CloseDate = system.today().adddays(-2);
          opp.recordTypeid=devRecordTypeId ;
          opp.ForecastCategoryName ='Pipeline';
          opp.ForecastCategoryName ='Pipeline';
          opp.Amount =200;
          opp.Topics__c ='Power Gen';
          opp.CurrencyIsoCode ='USD';
          opp.GEAC_Product_Area_of_Interest__c='DCS';
          insert  opp;
          Test.stopTest();

          Pricebook2 pb = new Pricebook2(Name='testDIE');
          insert pb;
          Product2 prod = new Product2(Name = 'Laptop X200',Family = 'Automation',Product_Line__c='COML IPC');
          insert prod;


         // PricebookEntry pbe1 =new PricebookEntry(unitprice=2,Product2Id=prod.Id,Pricebook2Id=Test.getStandardPricebookId(),isActive=true,UseStandardPrice = false);
          PricebookEntry pbe2 =new PricebookEntry(unitprice=2,Product2Id=prod.Id,Pricebook2Id=pb.id,isActive=true,UseStandardPrice = false);          
          insert pbe2;



          OpportunityLineItem olii = new OpportunityLineItem (Quantity=2, OpportunityId=opp.Id, TotalPrice=10.1, PriceBookEntryId=pbe2.id); 
          insert olii;

          BatchOpportunityInstallbase objBatch = new BatchOpportunityInstallbase ();
          Database.executeBatch(objBatch);

    }
}

Thanks

3
  • Why is your PricebookEntry pbe1 = new PricebookEntry(... line commented out? The error you're getting is complaining about the prod you're creating in the test not having a PricebookEntry for the standard pricebook. That one commented out line should (mostly) solve your issues (you'll need to insert that pbe as well).
    – Derek F
    Commented Jul 12, 2017 at 13:11
  • 1
    I rolled back your edit since having the code that isn't working is pretty important to giving a specific and accurate answer.
    – Derek F
    Commented Jul 12, 2017 at 15:45
  • Rolled back your edit again after a week of having your code removed with a promise that you would update your logic (but didn't).
    – Derek F
    Commented Jul 20, 2017 at 14:14

1 Answer 1

0

You are not giving the standard pricebook that's why this error comes.Provide the standard pricebook Id by this ways in you test class.

1.Pricebook2 pb2 = [select Id, Name, IsActive from PriceBook2 where IsStandard=True LIMIT 1];

2.Id pricebookId = Test.getStandardPricebookId();

1
  • ,Thanks for your reply .I have tried Using ablove SOQL and using Test.getStandardPricebookId(); like this "PriceBookEntry pbe2 = new PriceBookEntry (Product2Id=prod.Id, Pricebook2Id=Test.getStandardPricebookId(),isActive=true, UseStandardPrice=false,UnitPrice=0); insert pbe2;" But getting Error messages "System.QueryException: List has no rows for assignment to SObject"..Please Rephrase if anything is wrong in my logic..Thanks
    – Ram
    Commented Jul 12, 2017 at 10:04

You must log in to answer this question.

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