I'm trying to figure out how to limit the number of records my fast lookup is returning.

Use Case: We have customers who can redeem their points for rewards, like starbucks. For these Starbucks cards we load electronic codes. When the user want to redeem 100 points for 2 Starbuck cards I need a way to get two reward codes, not all available.

Let's say we have 10 codes available in the system and a user requests 3. I want to query the codes and limit the return to 3 to load into a collection.

How do I filter/limit the fast lookup to return only 3?


There is not a standard way to limt the fast lookup, nor the regular record lookup for that matter. A SOQL query in Apex could do this easy but I realize you may not want to go that route for various reasons. I have a sort of crazy idea that might work though. You could loop through the list of returned items and toggle a field on them to be 1, 2, 3, etc (use the assignment to plus 1 each time through). Then update the records (this would be some sort of hidden field). Then do another fast lookup whereby you filter for all records with the number <4 (or whatever the variable is you want to use). Then you take that list and do what you want with it.

Sort of clunky, but if you are committed to not using Apex it might work.

  • Thanks Mary for the input. I was able to come up with a solution kinda on the same lines as you suggested. What I did was a 'while loop' just using the standard lookup and assignment elements. I set a counter to track number of times I've iterated through with a decision element to compare the quantity to purchased with how many have been redeemed. I know this is causing some extra DML statements but we're not allowing more than a quantity of 10 at one time so hoping this want fall down. Link to design: screencast.com/t/eQ9yP3yB – Fifedog May 29 '15 at 17:52
  • Glad that works for you. If you used a true Loop/Fast update, then you'd only have one DML statement, then the lookup afterwards. That would protect from scenarios where this is an auto-triggered flow and you do a mass update/import. Just a thought. – mpusto May 29 '15 at 19:40
  • Totally agree... I'm a newbie with loops so still learning. I'll keep trying to figure this out with a loop/fast update. – Fifedog May 29 '15 at 21:26
  • The Flow workbook example in here: help.salesforce.com/apex/… for Reassign Accounts gives a good walk through of setting up a Loop and Fast Update. – mpusto Jun 1 '15 at 18:28
  • Yep, I'm working through that now. – Fifedog Jun 1 '15 at 22:11

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.