You need to sign in to do that
Don't have an account?
dai tran 6
How can add 2 Products have 2 Price book to a Order?
I have 2 Products:
Product 1 -> Standard Price -> 200$
Product 2 -> Promotional price -> 100$
How can add 2 this Products into a Order?
insert order:
insert order item:
It occur error:
Product 1 -> Standard Price -> 200$
Product 2 -> Promotional price -> 100$
How can add 2 this Products into a Order?
insert order:
Order od=new Order(); od.AccountId=con.AccountId; //od.ContractId=hd.Id; od.EffectiveDate=system.today(); od.Status='Draft'; insert od;
insert order item:
string searchquery='select ProductCode,Name,ImageName__c,(Select UnitPrice,Pricebook2.Name From PricebookEntries where IsActive=True Order By UnitPrice ASC ) from Product2 where ProductCode in ('+SOQL_IDs+')'; List<Product2> MyProducts= Database.query(searchquery); List<OrderItem> lsDetail=new List<OrderItem>(); for(Integer i=0;i<MyProducts.size();i++) { if(MyProducts.get(i).PricebookEntries !=null && MyProducts.get(i).PricebookEntries.size()>0) { String code=MyProducts.get(i).ProductCode; String sl=listCarts.get(code); OrderItem ode=new OrderItem(); ode.OrderId=od.Id; ode.Quantity=Double.valueOf(sl); ode.PricebookEntryId=MyProducts.get(i).PricebookEntries.get(0).Id; ode.UnitPrice=MyProducts.get(i).PricebookEntries.get(0).UnitPrice; ode.Product2Id=MyProducts.get(i).Id; lsDetail.Add(ode); itotalMoney=itotalMoney+ ode.Quantity * ode.UnitPrice; } } insert lsDetail;
It occur error:
Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Price Book Not Set on Order: []
Please go through the below link. Hope this helps you.
You need to set the PriceBook2Id on order.
https://salesforce.stackexchange.com/questions/49472/problem-with-inserting-a-new-order-item
https://salesforce.stackexchange.com/questions/202437/unable-to-set-pricebook-id-in-orderitems/202444
Please select as best answer if it helps you.
Thank You,
Ajay Dubedi
Product 1 -> Standard Price -> 200$
Product 2 -> Promotional price -> 100$
=> I have 2 PriceBook2Id =>Have i to insert 2 orders?
Either you create two orders or create only one order based on condition assign PricebookId.
Thank You,
Ajay Dubedi
You can explain a little about order management?
If a Cart has 2 Products:
Product 1 -> Standard Price (PricebookId =1) -> 200$
Product 2 -> Promotional price (PricebookId =2) -> 100$
Because if set PricebookId to Order, i have to create 2 Orders.
I feel not fine