Can any one help me out with this Error as :
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception:
PricebookEntryId, unknown (versions 3.0 and higher must specify
pricebook entry id, others must specify product id):
[PricebookEntryId, unknown]
Test class :
@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,
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='01ud0000004YWFqAAO');
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,
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='01ud0000004YWFqAAO');
insert OPplineitem;
}
}
2)Why do the code coverage displayed as None.
Any help very much appreciated.
Best Answer
Try the Below code to create OpportunityLineItem and everything related to it in Test class.
Hope this will solve the Issue as this is the Best way to create a OpportunityLineItem.