function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Max SmithMax Smith 

Dynamically Get PriceBookEntryID for OpportunityLineItem added through Process Builder

Hi All,

My salesforce org has multi-currency enabled.  We have a separate PriceBook (not separate entries in the same PriceBook) for all of our regions.  
 I have a custom object Professional_Services__c that is the child of Opportunity.  I have built a flow using the Process Builder that inserts/updates an OpportunityLineItem whenever a  Professional_Services__c object is inserted/updated.  

The PriceBookEntryID of the OLI will vary based on the PriceBook associated with the Opportunity (e.g. OLI will have a GBP PricebookEntry if Opportunity Pricebook is GBP, USD PricebookEntry if Opportunity Pricebook is USD).  
User-added image
The obvious problem here is that currently I'm forced to hardcode the PriceBookEntryID.  So when I migrate this process to production, I would have to change the PriceBookEntryIDs to those in Production which would be annoying but not showstopping.  The showstopping part is that this breaks my tests, which I need to migrate to production.  The tests generate PriceBooks, PriceBookEntries, etc. to prevent all of the pitfalls of using the (SeeAllData=true) annotation.  Is there any possible way to dynamically reference the PriceBookEntryID in the Process Builder?

As a side, because of the order of execution, I cannot accomplish this task using triggers, as relevant values from roll-up fields wouldn't be populated.

Thank you all in advance for your time,

Max
Parker EdelmannParker Edelmann

Hello Max,

I don't know too much about Custom Settings and Custom Metadata Types, as I haven't actually used them, but I've quite a bit about them and they may help you here. In a nutshell for this use case, you can lookup Custom Metadata in Visual Workflow and change that Custom Metadata without changing the flow itself.

What I'm proposing that you do, is to create a Custom Metadata Type that would store the Price Book Entry ID which you would then be able Lookup in Visual Workflow with a Record Lookup element to find the ID; you would not have to hard-code it in flow.

As I mentioned, I haven't actually used Custom Metadata Types, so I can't explain it too well, but here are some resources that may help:
https://trailhead.salesforce.com/module/custom_metadata_types
https://jenwlee.wordpress.com/tag/custom-metadata-type/

I hope this helps and I'm sorry that I can't give more help.

Regards,

Parker

Ernest FullertonErnest Fullerton
Max, I'm facing the exact same issue - have you come across a solution for this?