public class testBilDrugExcutiondetail
  static testmethod void testDrugExcutiondetail()

  Account a=new Account();
  insert a;

Order o = new Order(name='Test1', EffectiveDate=system.today(), AccountId=a.id, status='RFP Creation');
 insert o;

 OrderItem oi = new OrderItem(OrderId=o.id,PricebookEntryId='test');
            insert oi;

 system.assertequals('RFP Creation',o.status);
 PageReference pageRef = Page.Bilcare_Drugs_Execution_Details;
 ApexPages.StandardController sc = new ApexPages.StandardController(o);
    Bilcare_Drugs_Execution_Details d1= new Bilcare_Drugs_Execution_Details(sc);

  • i am getting error like System.StringException: Invalid id: test – Siddharth Potawale Nov 22 '16 at 5:58

While inserting OrderItem, PricebookEntryId is expecting an id value. Replace test string with PricebookEntry record id. So you need to insert PricebookEntry record.

Product2 prod = new Product2(Name = 'Test Product', 
                     Family = 'Test');
insert prod;

Id pricebookId = Test.getStandardPricebookId();

PricebookEntry standardPrice = new PricebookEntry(
                      Pricebook2Id = pricebookId, Product2Id = prod.Id,
                      UnitPrice = 100, 
                      IsActive = true);
insert standardPrice;

OrderItem oi = new OrderItem(OrderId=o.id,PricebookEntryId=standardPrice.Id);
            insert oi;
| improve this answer | |
  • Hi Reshma, I have tried this but now i am getting error like System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoPopulatePricebookEntry: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.AutoPopulatePricebookEntry: line 3, column 1: [] – Siddharth Potawale Nov 22 '16 at 6:43
  • AutoPopulatePricebookEntry trigger is causing the issue. What is there in that? – Reshma Nov 22 '16 at 6:45
  • we set the default standard price by using trigger. – Siddharth Potawale Nov 22 '16 at 6:49
  • This would be a different question – Reshma Nov 22 '16 at 6:57
  • 1
    You cannot ask all these questions in one thread. If you need us to help then post as a new question with code. – Reshma Nov 22 '16 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.