2

I have a custom object SapLine which is like opportunityLine, i.e has a product2 lookup field. The hierarchy is Opportunity-->OpportunityLineItem, SapOrder-->SapLine. I created a PricebookId field on SapOrder, which is populated from Opportunity.Pricebook2Id.

And two triggers:

  1. After insert on OpportunityLineItem - creates a SapLine and populates the product field with a product from OpportunityLineItem. Works fine.

  2. After insert on SapLine - creates an OppLine and populates fields, the problem is that I cannot simply pass Product2Id, because the field is not writable. I need to use PricebookEntryId field but how do I get the pricebookEntryId from SapLine?

I thought of adding a before insert on SapLine where you would populate a custom field pricebookEntryId, to later use it for OppLine.PricebookEntryId using the following method:

Having SapOrder.PricebookId and SapLine.Product2Id I can SOQL PricebookEntry

[SELECT id FROM PricebookEntry WHERE Product2id IN: lstOfProducts AND Pricebook IN: lstOfPricebooks]

How do I map pricebookEntryId to a specific SapLine?

  • It's kind of hard to tell what you are asking with such a brief title. I tried to clean it up but I'm not certain of your question, so that makes it difficult. – Adrian Larson May 10 '17 at 16:30
  • Should I rewrite the question or the title? – Alan Abishev May 10 '17 at 16:36
  • I'm not sure. Mostly the body; we can help with the title if it still needs refining after that. Are you using just one pricebook? If you are using multiple, do you know which one a given SAPLine corresponds to? Do you know the Product2Id on the SAPLine and just need to get the corresponding PricebookEntry? – Adrian Larson May 10 '17 at 16:40
  • I'm using multiline Pricebook and use a PricebookId__c field on SapOrder(SapLine's Parent) and Product2Id is known as well. I just need to find a corresponding Pricebook Entry – Alan Abishev May 10 '17 at 16:53
  • What is OppLine in the second point? Is it a custom object or the standard OppLineItem – anmrk May 10 '17 at 19:27

Your Answer

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

Browse other questions tagged or ask your own question.