You need to sign in to do that
Don't have an account?
king s 8
Apex Test Class For Opportunityline item
Throwing this Error :"System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Product ID: id value of incorrect type: 01s2800000DYoWpAAL: [Product2Id]"
Please Help me on this
Regards
kullayappa
@isTest private class updt_opty_testclsss{ @isTest static void testCallout() { //Opportunity opty=[select id,Name,Amount,Business_UnitId__c,Opty_num__c From Opportunity Limit 1]; Opportunity opty1=new opportunity(); opty1.name='testing'; opty1.CloseDate=system.today()+1; opty1.StageName='Closed Won'; insert opty1; OpportunityLineItem optyline=new OpportunityLineItem(); Product2 prod = new Product2(Name = 'Laptop X200', Family = 'Hardware'); insert prod; Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true); insert customPB; PricebookEntry customPrice=new PricebookEntry(unitprice=1,Product2Id=customPB.Id, isActive=true,UseStandardPrice = false); insert customPrice; optyline.Opportunityid=opty1.id; optyline.Quantity=1; optyline.Totalprice=10000; optyline.PricebookEntryId =customPrice.id; insert optyline; optyline.Opportunityid=opty1.id; optyline.Quantity=1; optyline.Totalprice=10000; optyline.PricebookEntryId =customPrice.id; update optyline; } }
Please Help me on this
Regards
kullayappa
There is a small mistake in the code. At line 18, you are assigning Pricbook Id to Product Id. That's the exception is " FIELD_INTEGRITY_EXCEPTION".
Please find below link which might help you:
http://stackoverflow.com/questions/9164986/how-do-i-avoid-standard-price-not-defined-when-unit-testing-an-opportunitylineit/15259316#15259316
https://developer.salesforce.com/forums/?id=906F0000000AeOcIAK
Let us know if that helps you.
Best Rgards,
BALAJI
I got the Isseue Thanks For your Reply,
Regards
kullayappa
Please close this thread so that it can be useful to someone else with similar issue.
Best Regards,
BALAJI