Use Case: Auto-Generate Multiple Lines Of Opportunity Product
* Updated at Mar. 25, 2021. The original flow is not optimal for the performance.
This flow uses creating multiple lines of products as example, but it can be customized to work on all kinds of objects.
Lulu Mobile provides phone subscriptions and uses the standard Opportunity and Product objects to track their sales. They provide various subscription plans and has a model of “Commit for more years, get more discount”. The company is not using CPQ and wants to have a super clear overview of how many years each customer has committed to, thus they do not want to use Schedules and want to have one product line per year.
The problem can be solved by a screen flow, or a record-triggered flow with a custom field. Since we do not want to increase the time spent to add the products, we will choose the second method.
Record-Triggered | Assignment | Variable |
Create Records | Counter | |
Decision | FormulaFormula | |
Update Records |
Does the solution solve your problem? If not, write us what your problem is and we will build the flow for you!
Saw you on Reddit… this looks awesome. Love to see a flow that sees a new record as a Lead and sends an email thanking them for filling out the form (that creates the lead on the web site) and checking out our web site. I used to be able to do this in Agile… haven’t quite figured out Salesforce yet, but I am learning.
Hi Rachel, thanks for the nice words! So If I understand correctly, you are hoping to send auto-response after you capture a lead from a website form?
If so, it seems like Lead Auto-Response Rules might be a better solution than Flow.
Take a look and if it is not what you are looking for, feel free to reach out again and let’s work on a better solution.
Love the article and idea! I’m trying to implement it Order and OrderItem, but I’m getting Too Many SOQL queries when I use more than 5 in the How Many Lines field. Is there a way to build in a delay?
Hi Kevin, I am very glad to hear that. I revisited the flow and found that the flow might not be optimal, so I updated the solution and hope that this can resolve the issue of potentially reaching the limit. I suggest trying the new solution and let me know if it’s working.
Another thought is that even the previous flow was not optimal, it shouldn’t call that many SOQL queries either, so it might be that there are other automation rules in your org that also fire up and thus reach the limits. Building a delay in record-triggered flow is not yet available unfortunately, but we might be able to resolve this by updating other processes.
Give the new solution a try first, and we can work on the troubleshoot if the issue still happens 🙂
THANK YOU SO MUCH! This works perfectly!
I agree, need to optimize some other processes. Still learning 🙂
I am really glad it helps! Yeah using Flow is like a trial and error process which never ends, so reach out anytime if there is anything I can help!
This is so great! It’s my first “official” flow. THANK YOU so much for the step-by-step instructions and screen shots!
So glad that it helps Megan! Good luck with all the future flow building 😀
Hi Melody,
I appreciate your straightforward, graphic flow explanations. Although an administrator for a some time I have found learning flow elusive. Hopefully will get better!
I have been trying to use your example as a template for my own flow but find myself getting stuck in one place- the dynamic date value is supposed to increment from each prior assignment value- but i’m finding the initial date formula value is set each time resulting in duplicates, rather than the previous incremented single record var date .
In my scenario the date increment is weekly and its an update flow from an initial record being set with a trigger being set from certain pick-list choices. I don’t have a number value that sets as the default base for the counter in a create scenario like you do. I also have native duplicate finder so this process fails (though i can see it in the debug)
The confusion for me is to have the formula incremented date in the single rec var be the object of the increment not the original next date formula repeated over and over again.
Do you have an idea what might be going awry here?
I have to admit that it was a little fuzzy for me analyzing your demo where I couldn’t figure out how this base date value was set in the first place given the date is not in the 1st assignment but rather the 2nd assignment where’s it’s the next date formula, along with the counter -1 that then passes to the collection var.
I think once I can have the first increment value being set on the first assignment to be set as the reference for the next date formula I will have this solved
Thanks for any help
Best
Jon
Hi Jon, it is a bit difficult for me to grasp the problem here, but essentially for the date to increment, we need two resources – (1) a date variable that stores the “current(last) product date” and (2) a date formula that stores the “next product date”
The steps are as below:
— Loop
Update the next product with (2) **
Update (1) with the value of (2)
— Loop
This way (2) will carry on to have a new value. I do the process like this because I don’t need to include the first “current product date” (That is from the previous product that I am cloning). I put the step 2 in a second assignment is because sometimes the assignment could work funky. The second one is needed anyways to add rec single to collection, so might as well just update the date and counter there too.
If I understand your case correctly, the first value on your (1) comes from a picklist and should be included. In that case, you will have to do this instead:
Set the (1) with the desired date
— Loop
Update the next product with (1) **
Update (1) with the value of (2)
— Loop
You can see the first step in the loop is different, depending on whether you want to include the first date or not. I hope this explains the situation somehow, but let me know if anything is still unclear.
Hi Melody, to break down your explanation, in your instance you update the formula first then update the variable with the value assigned in the formula and loop.
In my case, I would be updating the variable first (with whatever is supplying the first date to increment) then updating the variable with the formula value and loop
is that right?
The start value for your single record variable (or current value for the very first iteration) and what supplies that is key to what I’m missing I think. Because your initial assignment to the single record variable is not including the dynamic value for the Date,and somehow you are appending the incremented single record variable with that date on the 2nd assignment step and passing it thru to the collection variable from the single record variable then making your second pass with the same process.
Obviously your process works (your video proves it, ha!) I just need to somehow do the simplest version of this and build out. Thanks for your input/patience
Best,
Jon (aka Flow grasshopper)
PS The one thing that makes this moot unfortunately is that I now realize each iteration needs to populate the previous appt date field with the previous record id in chain of lookups between1-2-3-4. This is an after update scenario where the id is available after it is created – at least I think?
I don’t think these ids would available if I create all 4 at once, are they? i would need to be able to specify the right lookup id to each of the 4 new records.
Hi Jon, if you look at my step 6, I actually assigned a default value to my date variable. That’s why I didn’t need to have an additional assignment to give the first value.
In short, our processes should be the same. But instead of updating your date field with formula (from step 7), you should update your date field with the date variable (from step 6). This will make the difference of whether the first date will be included.
Regarding the chaining Ids, there are two ways to do so. The easiest way is to use Create Records multiple time if you are certain it can be within the DML limits. Alternatively, you can still create all records together using the collection. The Id will be populated back to the collection, so you can create another loop to populate the lookup. However this will require you create a Counter and a PreviousId variable (Counter is for skipping the first record; PreviousId is for storing the record from the previous iteration). This could be a complex use case if you are just starting with flow, so if you would like to see a specific use case on this, feel free to submit a case and I can arrange it into the schedule. (Would take a while before it can be published though)
Thanks Melody, I guess I need to take this one step at a time. succeed and then add a piece. At my level i don’t think there’s any other way. With so many things not working at once, I would be just building on confusion (as Bill Evans, the great jazz pianist once said)
Thanks again for your patience and input. Look forward to seeing your new posts.
Melody – question. Supposing the DML limits were not violated in multiple. create. How would the newly created record ID go for the next record to access in the lookup – where does that new Id go.? My assumption here is that the loop would be a cycle – Start – then a simple 3 part loop until counter is 0:
Decision —> Assignment (w/Decrement) —> Create —> Decision –> Assignment, etc
Or is that wrong?
Hi Jon, the newly created record Id will be populated back to the variable that is generated from the Create Records element.
If you create using a record variable – the Id will be stored back to that record variable.
If you create with conditions – a new variable will be created, or you can assign the ID to a specific variable.
If you use the Create Records with the Current Item variable, you will have to create another text variable and then store the ID to this variable with an Assignment after record is created
Melody thanks!
But what how would you find these new variables created from the Create Records element if you were to look it up in Resources?
Does it have a standard systematic name?
Like here’s some made up ones:
{!CreatedRec1.Id} –>{!PrevApptVar1} —>CreatedRec2.PrevAppt__c
{!CreatedRec2.id} —>{!PrevAppt?Var2} –>CreatedRec3.PrevAppt__c
etc
something like this?
Hi Jon, not sure if I understand what your example means, but if you create records with a variable, the Id will be replaced. If you create with conditions, a new variable will be generated like in screenshot. You can also check out this video for details:
https://www.youtube.com/watch?v=riHNuoKcKgQ
Hi Melody.
i think your video mostly explains it. it was how to identify the Created Record ID. In your example it looks like it explains it. And some of it will become more apparent if I connect more steps to the Created records on the canvas.
For the Collection Variable it’s not quite as clear how to segregate each ID so that you can then use them in a follow-up assignment step. (For example the one I described where the Previous Appt lookup on Record 2 is populated from Record 1). You did mention generally that it could be done with a counter and that you might do a follow-up if the public clamors for it (lol). Right now I’m one person 🙂 I want to try to take a stab at it. But of course I’m a beginner
Don’t mean to monopolize your thread here. i appreciate all your answers
Best
jon
No worries Jon! If you have the Create Records in the loop, you will need to store the newly created Id in a variable at the end of each iteration, and then you can use the Id in the next iteration (then it will get updated again at the end)
In short, if you have the Create Records in the loop, only 1 element is needed (this Create Records will be used repeatedly), and you need the additional variable to store the previous created record
If you have the Create Records outside the loop, you will need as many elements as how many you are creating (ex. 4 elements for 4 records), but the additional variable is not needed.
Hope this makes sense!