1

I am trying out the scheduled Flows.

Should i use the filter option on the start element to filter the records or should i use the getrecords to get my records that i need to work with.

If i do use the filter option in the start element then while updating the record would it hit any limits?

If i use the getrecords then i could potentially hit the limit of no of records queried?

The usecase is

Query all leads which have NoOfDaysForExpiration < 0 ( i can potentially filter this on the start element)

Change the owner to an user (I can do an assignment on the $record)

Then update the record. (would it cause an limit issue?) Can we move the record into a collection variable and update it towards the end ? (I am not sure how we update the collection after all the records in the batch is processed)

Or

Dont provide any filter in start

Use the getrecords to get the records(filter here)

Loop through the records and make an assignment and then add it to a collection variable and then outside of loop update the collection

What would be the best practise?

2 Answers 2

2

Using the Start element's filters allows Salesforce to handle the transaction size automatically so you don't have to. This actually runs as a hybrid scheduled/batched job. This is explained in the documentation:

Schedule an autolaunched flow to start at a specific time and set it to run once, daily, or weekly. To have the scheduled flow run for a batch of records, specify the object and the filter conditions that each record must meet.

A flow interview runs for each record in the batch and stores all of the record’s field values in the $Record global variable. As you build the scheduled flow, reference the $Record global variable to access the record’s field values.

This also eliminates your concerns about adding records to a Collection and trying to update them somehow. That's actually rather trivial, but an unnecessary step, since the Start element's filter is purpose-built to handle this for you.

Note that even though it seems like there'd be one DML for each record at the end, there's only one, because of Flow Bulkification, as explained:

When multiple interviews for the same flow run in one transaction, each interview runs until it reaches a bulkifiable element. Salesforce takes all the interviews that stopped at the same element and intelligently executes those operations together. If other interviews are at a different element, Salesforce then intelligently executes those operations together. Salesforce repeats this process until all the interviews finish.

4
  • 2
    Very surprising somebody just did a -ve vote for a @sfdcfox answer and didnt explain why . Infact 2 -ve votes. As always you are the best
    – Prady
    Oct 20, 2022 at 12:46
  • @Prady Looks like revenge voting, if you ask me. I'm not worried about it, I don't do this for the rep anyways.
    – sfdcfox
    Oct 20, 2022 at 13:40
  • only way to filter start element for recordtype is to hard code the Ids, also no relative dates yet in start element, so for those reasons one may want to consider the latter. you can use a decision for this within the scheduled flow, but then its running on lots of records unnecessarily which is only an issue if you are running into scheduled flows per day limits
    – gorav
    Nov 3, 2023 at 13:04
  • Another concern with using the Start element's filters is that, at the time of writing, you can't specify a sort. This can lead to UNABLE_TO_LOCK_ROW errors on Accounts that have Opps that need to be updated but are in different batches, as explained here salesforce.stackexchange.com/questions/354660/…. As far as I can see, a 'Get Records' with sort is needed to get around this.
    – MikeA
    Feb 1 at 13:22
-1

The second approach that you had posted is the best. As there will be only one dml at the end. So you need not to worry about hitting the salesforce dml limit.

1
  • 1
    The Start filters simplifies the flow considerably and allows Salesforce to handle the transaction size automatically. There's no benefit that I know of from using Get Records over the Start element filters in this use case.
    – sfdcfox
    Oct 20, 2022 at 12:07

You must log in to answer this question.

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