2

So I'm new to using flow and i'm doing something wrong. Hoping someone could help to get me on the correct path.

I have a very simply flow that I'm trying to do that involves pulling a record collection from the Subscription object and creating a new record for each record in the collection in a custom object called Entitlements using only 4 of the data points.

My preference is to have the bulk create work and not have to loop through, but I cant seem to get that to work so I tried looping through and creating the records within the loop, but that does not seem to work either.

Here is what is currently setup with the loop. When I run, I do not get an error, but the records are not being created. The fields I'm trying to include are:

  • Account ID (Destination field is Lookup)
  • Contract Number (Destination field is Text)
  • Product Name (Destination field is Text)
  • Product ID (Destination field is Text)

Any help is massively appreciated

enter image description here

3
  • Ahhh I got the loop working. It was a simple mistake of assigning the incorrect Record collection.
    – Shawn M
    May 15, 2020 at 20:59
  • You want to avoid creating records in a loop. In the loop use a second assignment to add the variable to a collection, and then once the loop finishes use a create records element to insert the full collection in one step. This will bulkify better.
    – gorav
    May 17, 2020 at 14:30
  • Paste your debug log here, please. What does it say? May 18, 2020 at 2:08

2 Answers 2

3

Avoid creating records inside a loop. It might fail if there are too many records. Also, it's not the best practice.

You can create a record variable of type 'Entitlement', assign the field's values for Entitlement record inside the loop, and add this variable to the Entitlement record collection variable.

Use a single 'Create Records' element after the loop and insert the Entitlement record collection variable.

Edit

Adding an example:

enter image description here enter image description here enter image description here enter image description here enter image description here

3
  • How do you add add the record variable to a collection? This is the part I'm struggling with. I'm guessing a second assignment where I set the the Variable as the Collection, Operator as Add, and the value as the Record.field?
    – Shawn M
    May 18, 2020 at 18:39
  • Yes. I have added an example for your reference. May 19, 2020 at 5:13
  • 1
    You are the man. This helped. My flow is now working. No more creating within the loop.
    – Shawn M
    May 19, 2020 at 16:56
0

Yes, we want to avoid the pink inside the loop as much as possible.

  1. Create a record variable: Subscription.
  2. Create a collection variable: Subscriptions.
  3. In a Loop, use an Assignment element to assign values to fields in the Subscription record variable.
  4. Make the Id field blank if you intend to use Create Records. For Update Records, of course, Id needs to be populated.
  5. At the end of the Assignment as the last step: Subscriptions>Add>Subscription.
  6. After the end of the loop, use a Create or Update with the Multiple option and Subscriptions as the collection.

An example below shows my Configuration Component (CC) Records being generated and added to a collection in this way.

I just want to comment for others' benefit that I had an older flow that ran API version 52, and the above steps did not work properly because the fields did not get properly assigned when I had the Collection>Add>Record in the same Assignment element as the field assignments. Changing it to version 57 fixed that. This is my main reason for writing this answer. Hope it helps someone.

An example from one of my flows

Assignment Element

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .