Go with the Flow volume 2: The Assignment thingee
So last time I extolled the greatness that are SObject variables. This time I'm going to try to explain what in the world an Assignment is and how they can be used to help make your flows more efficient. I will say that because this is a multi-post tutorial, a lot of the stuff I'll write about will make more sense down the road as we begin to weave the elements together to create flows that are crazy awesome.
So yeah, Assignments. These are like the duct tape of the flow - they can be used to do a lot of things. So to help break it out a little more, I think it's useful to think of the Assignment as having two main purposes:
Setting up records that are going to be created/updated/deleted
So this is part one of how they can be used to be more efficient than using the normal record create/update delete elements. When setting up an assignment, you'll notice that you can do quite a few things with them - where we will talk about using them in this section is with SObject variables. Remember last time we wanted to create a chatter post on the account for the opp? What if we wanted to post on the Account AND the Contact if it is there (we're going to assume it is for the purpose of this example)?
Let's see how we can use the SObject variable and the Assignment element to set up the two records. When you add the Assignment element, this is the setup screen you'll get:
You'll see that I have set up 2 new SObject Variables - one for the Account feed post and one for the Contact feed post. You can kind of see some text hiding behind the dropdown box with the sobject varaibles, that just says Add Assignments. This means you can make more than one assignment per Assignment element, for us that means we can set all the field values for the Account and Contact feed post in one go.
When done, it will look something like this (I went ahead and added some markup because those darn SObject Variable names are so long):
Remember the SObject variable we created last time? We are using that to populate our new feed items. So here we have two FeedItems setup with a ParentId and a Body just begging us to do something with them. But how to get them from potential FeedItems to actualized FeedItems?
Telling the flow which records to create/update/delete
I'm glad you asked that! The second way to use the Assignment is to add records to an SObject Collection. We won't get too much into that as I'll tackle that in my next post, but for the purpose of explaining Assignments, this is HOW you do something with the SObject Variables you set up using an Assignment element- and this is where the Salesforce Automation rubber meets the Business Process road. Above we set up two records by using an Assignment to set the values for the FeedItem fields, now we are going to put them somewhere where we can actually do something with those records. In the section above, we used the "Equals" operator to set values; here we are going to use the "Add" operator to make those two SObjectVariables we set up useful. It will end up looking like the image above.
Basically, we used the Assignment to tell the Salesforce to put theAccountFeedItemRecord and theContactFeedItemRecord into a list of FeedItems that we can use to insert. All that is left is to use a Fast Create action to take the records in that theFeedItemsToInsert SObject Collection and actually create them. It'll look a little something like this:
And the final product? A single DML statement to create TWO FeedItems on TWO different records!!!!
Now this might seem a small feat, but when we get to later volumes of this tutorial, it will mean the difference between 400 DML statements ( and the ensuing Flow email error!) and ONE DML statement when mass closing 200 Opportunities as Closed Won. So yeah, let that sink in for a minute.
Next up, SObject Collection variables!
Note: I know you can also use Assignments to fill out normal ol' Collection Variables, but this is my attempt to demystify the flow stuff, and talking about that right now would just re-mystify everyone, including me!
Gray Dowsley ? Tara McDermott Mitchell Blanchard oh yeah, #GoWithTheFlow is a thing now.