Visual Workflow – Should Records Be Filtered in Start Element or Use GetRecords?

scheduled-flowvisual-workflow

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?

Best Answer

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.

Related Topic