I am adding an Opportunity Line Item within my Apex code. When I create a Quote, I would like that quote to sync automatically and use the Opportunity Line Item and copy it in the Quote Line Item. I can reproduce that if I am not using my Apex Code. Any idea why it will delete my opportunity Line Items when syncing?
Code:
for(Integer y = 0, aValue = recList3.size(); y < aValue; y++){
OpportunityLineItem oli = recList3[y];
List<PricebookEntry> pbe = [SELECT Id FROM PricebookEntry WHERE Pricebook2Id = '01s6g0000037ZybAAE' AND Product2Id =: recList3[y].Product2Id];
oli.PriceBookEntryId = pbe[0].Id;
}
This is what I am passing to recList3
[{"Name":"ProductXYZ","OpportunityId":"0068A...","Product2Id":"01t6g0...","Quantity":"1","UnitPrice":"1"}]
For each product in recList3, I am assigning the PricebookEntryId.
Let me know what I am missing. Thanks