Retrieve customized information from opportunity products

Prev Next

Candace, the best sales rep of the Cloud Kicks team, needs to fill in additional information in a custom text field on the opportunity product.
This custom information helps the customer understand the products purchased in addition to their official description.
One day, a customer calls Candace not understanding her invoice. To her dismay, Candace discovers that the information was not displayed on the Invoice PDF.
She then turns to Linda to see what can be done to display this information.

Linda investigates and discovers that the additional description field has been created on the Invoice Line but is never filled in. So she tries to set up an automated way to retrieve the opportunity product information.
Unfortunately, she reaches a limitation of the Salesforce platform: it is impossible to create a lookup field for opportunity products.
Fortunately, Frisbii anticipated this problem and filled in a text field with the ID of the opportunity product from which the invoice line originates.

Linda can't do a simple process because it doesn't handle text-based IDs.
Linda reassures Candace, rolls up her sleeves and opens her configuration to set up a flow.

Prerequisites

You need to know the field whose values are to be copied from Opportunity product to Invoice line.
You need to create a field of the same type with the same characteristics (length, selection list values, number of decimals…) on the Invoice Line as on the Opportunity product.

Flow setup

Linda starts with the creation of a flow. Following the Trailhead units she has done on this subject, she is confident that she will get it right the first time.

Steps

1. Open the Setup.
2. Type Flow in the Quick Find search.
3. Click on Flows in Setup > Process Automation > Flows.

  1. Click on New Flow at the top right.

  1. Choose Record-Triggered Flow

  1. Choose Auto-Layout

  2. Click on Edit in order to set the Start conditions.

  1. Keep a record is created and select Before the record is saved.

  1. Click on Done

  2. Click then on + Choose Object in the Stard box

  3. Select Invoice Line Item, select None for the conditions and click on Done without entering a condition.


12. Click on the + icon and select the Get Records item. Enter the label for this item. For example Get Opportunity Product.
13. Enter a description that will allow anyone to understand what this item does. For example: Retrieves the opportunity revenue associated with the invoice line.
14. Search for "Opportunity" in the Objet field.
15. Select Opportunity Product.



16. Now the conditions are available. Choose in Field Id and keep the operator at Equals.
17. Click into the Value field.
18. Click on $Record at the end of the list.


19. Type opp to bring up the choice sofactoapp__OppLineItemId__c which is the field that carries the id of the opportunity product from which the invoice line originated.
20. Select this choice.

Beware: If this field is empty the flow will block. This flow must be completed if all your invoice lines are not issued from or linked to an opportunity product. This is for example the case if you create invoices ex-nihilo or if you never use the opportunities.

  1. Keep the other default values and click on Done at the bottom right.


22. On the + icon between the Get Record Element and the End item select Assignment.
23. Enter the label for this item. For example Fills in the custom fields on Invoice Line Item.
24. Enter a description that will allow anyone to understand what this element does. For example: "This assignment allows the fields on Invoice Line to be populated with the values of the fields on Opportunity Product.".
25. Click on the Variable field.
26. Choose $Record.


27. Find the field to be filled in, here: Additional description and select it. Leave the operator as is.
28. Click on the Value field on the right to highlight it.
29. Select Opportunity Product from Get Opportunity Product.


30. Select the source field on Opportunity Product, here : Additional Description.

  1. If you have more fields to synchronize, you can click + Add Assignment and repeat steps 25 to 30, otherwise click Done.

  2. Click on Save at the top right.


34. Fill in the label of the flow. We advise you to always have the same nomenclature.
Here, we start by describing the type of automation (flow), then the object on which it is based (Invoice line) and finally its triggering mode (before insert).
For example, here we have: Flow - Invoice line item - before insert.
35. Also fill in the description. For example here: This flow in before insert (before inserting the record in the database) retrieves the custom information of the opportunity product and fills it in the invoice line.
36. Click Done.

  1. Finally, click on Activate at the top right.

Testing Approach

Linda and Candace are eager to test Linda's flow. Let's see how they proceed.
 

Steps

1. Open an opportunity record.

2. Click on a product record in the related list.


3. Enter a value in the field or fields to be retrieved. Here Additional description.

4. a) Click on Save.



4. b) Then go back to the parent opportunity and click the Create invoice and Confirm button on the intermediate confirmation page.


5. You should now be on an Invoice record. Go to the invoice line associated with the opportunity product where you had entered a value, in this case Sneakers Winter 20.


6. The information must be correctly present on the invoice line item. Here the Additional Description field is filled with the value previously entered on the opportunity product.

 

Appendix: if invoice lines are without opportunity line item

This flow does not handle the case where the invoice line is not linked (directly or indirectly) to an opportunity product. Please find here the procedure to add a control in order to handle this exception and avoid errors.
 

Steps

0. Re-open the flow.
1. Click and drag a Decision item from the toolbox.
2. Fill in an explicit label.
3. Enter a description.
4. Enter an explicit label for the result details.
5. Fill in the resource by choosing $Record and the OppLineItemId field
6. Change the operator and choose Is null
7. Fill in the value with the global constant False.
8. Click on Done.

  1. Click the arrow that connects the Start and Get Records item to highlight it.

  1. Tap the Delete or Backspace key to delete this connection.


10. Tap the Delete or Backspace key to delete this connection.

  1. Connect the Start and decision item to Get Records box. Select the Yes - there is an opportunity product outcome and click Done when connecting the decision with Get Records.

  2. Click on Save As.

  1. Leave as is or complete the description and click Save.

14. Finally, activate this new version.

 

Beware of your org's performance

A before insert flow is the one that will ensure the best performance for the automation.

However, this does not mean that it is sufficient in case of mass creation of invoice lines.
For example: generation of billing schedules at the same time on several subscriptions from opportunities.
Please test that this automation does not negatively impact your org by reaching limits.

This flow does not manage synchronization.
A modification on the opportunity product will not be distributed on the associated draft invoice lines.