Optimising Record Counting Flow - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Nitzan MarinovNitzan Marinov 

Optimising Record Counting Flow

Hi everyone,

I built a flow that needs to do the following:
  1. Get all payment records for the opportunity
  2. Sort them by Scheduled Date
  3. Update a text filed (called Payment Counter) with this value: 
    1. Payment 1 of 3
    2. Payment 2 of 3
    3. Payment 3 of 3
One of the issues I'm having is that the way I built it isn't optimised as per this tip:
Tip

I know I need to take the Record Update out of the loop but I'm not sure how to update a variable to hold the value for each record and then do a single record update.

Here are other screenshots of what the Flow looks like:

Flow

Get Payment Records & Loop:
Loop Payment Records
Assignment:
Assignment
Update Payment Records

It would be great to be able to learn how to optimise the loop performance, so thanks in advance.

Nitzan
Best Answer chosen by Nitzan Marinov
Nitzan MarinovNitzan Marinov
Thanks, Ankush!

I think I was able to work it out with your tips (to be exact, the flow works. I just hope I wrote it as efficiently as possible).

Here is what it looks like now:

1. Flow Outline - 
Flow Outline
2. The Loop Payment Records loops the Payment records that we got in the 1st step
3. I split the assignments to 3 blocks. Based on the testing I've done, I think that's the minimum I need.
 1. Update Payment Number & Total # of Payments - 
1. Update Payment Number & Total # of Payments
 4. 2. Update varPaymentDtl - 
2. Update varPaymentDtl
 5. 3. Update varPaymentUpdList - 
3. Update varPaymentUpdList
6. Update varPaymentUpdList Records (which updates the collection variable with the updated records)
Update varPaymentUpdList Records

Again, thanks for all your help!

All Answers

Ankush AgarwalAnkush Agarwal
Hi Nitzan,

You may need 2 variables to get this update records out from loop. First you below 2 varaibles:

1. PaymentDtl == Record type variable for Payment Object
2. PaymentUpdList == Record type variable for Payment Object with Alllow multiple refords checked <--- list of Payments

Update PaymentDtl with values as per requirement and from loop variable
Add PaymentDtl to PaymentUpdList
After loop completion use Update Records with PaymentUpdList and then screen for message to user.
Nitzan MarinovNitzan Marinov
Hi Ankush,

Thanks for responding.

I tried to follow your steps but I'm getting a bit confused.
  1. I created the variables you suggested
  2. Variables
  3. I updated them in the Assignment action:
  4. Assignment
  5. I tried to do the Update Records but I'm not sure it's correct:
  6. Record Update
  7. You say:  "After loop completion use Update Records with PaymentUpdList and then screen for message to user." But PaymentUpdList isn't available to me at this stage.
What am I missing?

Thanks
Nitzan
Ankush AgarwalAnkush Agarwal
Hi Nitzan,

You need to add 1 more assignment block to perform below operation:

varPaymentUpdList            Add         varPaymentDtl

After Loop Completion, in Update Records block, you need to mention varPaymentUpdList in list section insted of selecting the Payment object.
 
Nitzan MarinovNitzan Marinov
Thanks, Ankush!

I think I was able to work it out with your tips (to be exact, the flow works. I just hope I wrote it as efficiently as possible).

Here is what it looks like now:

1. Flow Outline - 
Flow Outline
2. The Loop Payment Records loops the Payment records that we got in the 1st step
3. I split the assignments to 3 blocks. Based on the testing I've done, I think that's the minimum I need.
 1. Update Payment Number & Total # of Payments - 
1. Update Payment Number & Total # of Payments
 4. 2. Update varPaymentDtl - 
2. Update varPaymentDtl
 5. 3. Update varPaymentUpdList - 
3. Update varPaymentUpdList
6. Update varPaymentUpdList Records (which updates the collection variable with the updated records)
Update varPaymentUpdList Records

Again, thanks for all your help!
This was selected as the best answer