You need to sign in to do that
Don't have an account?
ManishKSingh
Issue in unit test class of QuoteLineItem
I am creating unit test class for quote line item and it execute without any exception in sandbox but when i validate it in the production organization of salesforce, it's fail with following error "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [UnitPrice]: [UnitPrice]
Stack Trace: Class.Test_TriggerRollupPriceAndCost.testRollupPriceCost: line 48, column 1".
but [UnitPrice] field is already defined in the below class.
@isTest(seeAlldata=true)
public class Test_TriggerRollupPriceAndCost {
static testmethod void testRollupPriceCost(){
Account a=new Account(Name='Test');
insert a;
Opportunity o=new Opportunity();
o.Name='TestOpp';
o.AccountId=a.Id;
o.StageName='Test';
o.CloseDate=System.Today().addMonths(1);
o.LeadSource='test';
o.District_Sales_Rep__c=[Select Id from User where Name='Salesforce Uploader' limit 1].id;
o.Product_Line__c='Tet';
o.Type='Test';
o.Vertical_Market__c='Test';
o.Comm_Split_Primary__c=100.00;
insert o;
Product2 p1 = new Product2();
p1.Name='Test8';
p1.Productcode='PO16';
p1.IsActive = true;
insert p1;
Pricebook2 standardPB = [Select Id from Pricebook2 where isStandard=true limit 1];
PricebookEntry pbe = new PricebookEntry();
pbe.IsActive = true;
pbe.Product2ID = p1.Id;
pbe.Pricebook2Id = standardPB.Id;
pbe.UnitPrice = 200;
//pbe.UseStandardPrice = false;
insert pbe;
Quote q=new Quote();
q.Name='Test';
q.OpportunityId=o.Id;
q.Pricebook2Id=standardPB.Id;
insert q;
QuoteLineitem q1=new QuoteLineItem();
q1.PricebookEntryId=pbe.Id;
q1.Quantity=1;
q1.UnitPrice=pbe.UnitPrice;
q1.QuoteId=q.Id;
insert q1; // exception is here..
delete q1;
}
}
Plz help me to resolve this issue
Thanks in advance.
Stack Trace: Class.Test_TriggerRollupPriceAndCost.testRollupPriceCost: line 48, column 1".
but [UnitPrice] field is already defined in the below class.
@isTest(seeAlldata=true)
public class Test_TriggerRollupPriceAndCost {
static testmethod void testRollupPriceCost(){
Account a=new Account(Name='Test');
insert a;
Opportunity o=new Opportunity();
o.Name='TestOpp';
o.AccountId=a.Id;
o.StageName='Test';
o.CloseDate=System.Today().addMonths(1);
o.LeadSource='test';
o.District_Sales_Rep__c=[Select Id from User where Name='Salesforce Uploader' limit 1].id;
o.Product_Line__c='Tet';
o.Type='Test';
o.Vertical_Market__c='Test';
o.Comm_Split_Primary__c=100.00;
insert o;
Product2 p1 = new Product2();
p1.Name='Test8';
p1.Productcode='PO16';
p1.IsActive = true;
insert p1;
Pricebook2 standardPB = [Select Id from Pricebook2 where isStandard=true limit 1];
PricebookEntry pbe = new PricebookEntry();
pbe.IsActive = true;
pbe.Product2ID = p1.Id;
pbe.Pricebook2Id = standardPB.Id;
pbe.UnitPrice = 200;
//pbe.UseStandardPrice = false;
insert pbe;
Quote q=new Quote();
q.Name='Test';
q.OpportunityId=o.Id;
q.Pricebook2Id=standardPB.Id;
insert q;
QuoteLineitem q1=new QuoteLineItem();
q1.PricebookEntryId=pbe.Id;
q1.Quantity=1;
q1.UnitPrice=pbe.UnitPrice;
q1.QuoteId=q.Id;
insert q1; // exception is here..
delete q1;
}
}
Plz help me to resolve this issue
Thanks in advance.
[1] http://releasenotes.docs.salesforce.com/en-us/summer14/release-notes/rn_apex_price_books_in_tests.htm
All Answers
i am try the both scenario but it only works in sandbox, fail in the production organization withgiven exception
[1] http://releasenotes.docs.salesforce.com/en-us/summer14/release-notes/rn_apex_price_books_in_tests.htm
My apex class successfully deployed . The issue is in the workflow rather than unit test class. But your suggestion is very helpful for my future reference.
Thanks