2

I am launching a flow from APEX and I want to pass it a list of IDs. The issue that I am coming across right now is that I will need to look up each ID in the flow because there is no "IN" clause for getting records inside a flow.

The reason why I am launching the flow is that:

  1. I want our Admin to be able to really have control over the nuts and bolts over the code.
  2. We need to launch the flow asynchronously because it requires some extra processing that I was resulting in the following error:

    UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record

Unfortunately, as far as I am concerned there is no way currently to launch flows in an asynchronous context. So what I am doing is developing a method that fires in the "AFTER INSERT" context of the trigger and calls a future method that will call the flow. As stated above, I am just concerned that passing in a collection of IDs will result in a massive amount of SOQL Calls, which will ultimately cause me to hit governor limits.

1 Answer 1

4

Flows automatically bulkify, so passing in values shouldn't be an issue.

Process Builder

You don't need a trigger, as you could use a Process Builder with a Scheduled Action set to "0 hours after created date", which means "run as soon as possible." As long as you don't need more than than the hourly limit, you'd be fine.

Flow (Pause)

Or, you could use a Pause element in your flow set to 0 hours after Created Date, before doing any DML operations. This will have the same effect.

Queueable

Alternatively, you could use a Queueable, and call the flow with a chain, or even call one Queueable per a number of records (e.g. split into groups of 10). You get 50 queueable calls per synchronous transaction, which should be plenty for your use case.

11
  • Are you saying that Flow (Pause) will have it run Asynchronously? Commented Apr 18, 2020 at 17:10
  • 1
    @MatthewMetros Yes, a Pause will introduce an asynchronous delay.
    – sfdcfox
    Commented Apr 18, 2020 at 17:10
  • Ill take your word for it, but there is no documentation online that says this... So if this is the case, then flows can run in an asynchronous context. That makes me curious why this idea exists on the "Idea exchange"- success.salesforce.com/ideaView?id=0873A000000COJ1QAO Commented Apr 18, 2020 at 17:14
  • @MatthewMetros Right, read the top comment. That's what I basically just said.
    – sfdcfox
    Commented Apr 18, 2020 at 17:15
  • 2
    @MatthewMetros Because they'll be in a separate, asynchronous context, so they'll have the limits they need. And you have to write zero code, no unit tests, etc. The Pause gets you out of the synchronous context that's causing you problems to begin with.
    – sfdcfox
    Commented Apr 18, 2020 at 18:31

You must log in to answer this question.

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