3

I am brand new to Flow and I need to create a decision element based on criteria from a child record’s related records, or more specifically, from the Opportunity\Opportunity Line Items\Product2 field values.

Per the Product and Schedule Object’s entity relationship diagram (ERD), you can get to Product2 through the OpportunityLineItem via the PricebookEntry object, but in reality the Product2ID is available on the OpportunityLineItem. So, before adding a decision element, I figured I would test first and see what it took to produce the Opportunity Line Items associated Product2 fields but I get stuck halfway through.

I created a flow beginning with a temporary assignment of a particular OpportunityID (this will be replaced by Process Builder pushing in the OpportuntiyID later) to a variable.

I then run a Fast Lookup on the OpportunityLineItem where the OpportunityID equals my OpportunityID variable above, assign the records to an sObject Collection Variable and specify only the Product2Id field.

Next, I Loop through the opportunity lines in the sObject Collection Variable above, assigning the records to the Loop Variable sObject Variable.

The LoopVariable.Product2Id is then added to a Collection Variable in an Assignment and I close the loop from the Assignment back to the Loop element.

It looks like this:

enter image description here

When adding a screen element off the Loop to display the Assignment Element’s Collection Variable, it produces the expected results – it gives me all of the Opportunity Line Items associated Product2.ID’s. I have been unable to take this any further.

Theoretically, I would take those Product2.ID’s and run a Fast Lookup against them, but a Fast Lookup needs a Variable or sObject Variable as the filter value and my Product2.ID’s are now in a Collection Variable.

I have tried all combinations of Loops, Assignments and Fast Lookups to return specific fields from the Product2 object for my Decision element to ultimately be based on but I hit a wall every turn. I am sure I am overlooking something simple here as if I can produce a set of record ID’s, there is bound to be a way to use those ID’s to feed in to another subprocess. I am happy to provide any additional information if needed.

1

You could declare an sObject variable of type Product2 called "Prod" as well as an sObject collection variable with object type Product2 called "Prods". Each time through your loop of Opp Lines you would first populate the Prod variable by doing a fast lookup using the ID from the Opp Line, and then add to the Prods collection using the assignment element and add operator. At the end of this looping your Prods variable will contain a list of all the products you're interested in for the next step.

  • Thanks for the reply Monty, but if I am reading your response correctly, it leaves me with the same result that my flow above does - a collection of Product2 ID's. It's how to use them next that has me stumped. Being that I need to go from OpportunityLineItems to Product2 object types, I am convinced the issue is the same as referenced in the Visual Workflow Guide - Cross-Object Field References in Flows, and I am in the process of trying to understand how to apply the Simple Relationship syntax in my flow. If I am reading your response incorrectly, please, let me know and shed some light! – mbolton Nov 18 '16 at 14:25
  • No, my approach leaves you with a collection variable containing complete product data for all products referenced in your Opp Lines. It populates the sObject collection, one record at a time, as you go through each iteration of the loop. – Monty Ghitter Nov 18 '16 at 16:07
  • Ok, once I put a display loop on this, it worked as advertised. The piece I was missing in my original flow was doing the lookup to the related object and adding to a new collection in my initial loop. Thanks, Monty! – mbolton Nov 18 '16 at 19:17
-1

Since Winter 18, an exciting new feature has hit the tables, which makes it so easy, to deal with loops while working in visual flows.

Now looping through a collection of records, incrementing the counters is no longer needed. Instead the record count can be easily fetched in a sobject collection variable and assigned to a number variable. Play around with the count variable directly. So finding out the number of open/closed/in progress opportunities gets more easy. I can think of many more use cases that will be benefitted because of this feature.

So to answer this question, all you simply need to do is like:

  1. Perform a fast lookup with your required filters enter image description here
  2. Assign the record count to a sObject collections variable. (in screenshot: nofCases)
  3. Use a Assignment step, to assign the variable to a number variable. (Point to note: the assignment variable should be of type number only to make use of equals count operator. In the screenshot, this is called testCount) enter image description here
  4. Voila! Now play the hell around with the assigned variable :)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.