I have a requirement where:
- Whenever a case record is updated so that
Boolean__c = true && source__c = email- An async path will call a prompt, take certain actions like (trigger email alerts and close the case). This could be internally bulkified by Salesforce too, since we can have multiple cases created (and hence meeting this condition) in short span or same time. - From an LWC component, if certain button (say
Submit) is clicked - Only email alerts should be triggered and close the case. No prompt invocation. This is irrespective of whetherBoolean__c = true && source__c = email. This will strictly be only one record since UI interaction will happen from individual Case record page.
So what I have done is:
- Create a record triggered flow with - trigger as "A record is Updated", "Only when a record is updated to meet the condition requirements", and the condition is
Boolean__c = true && source__c = email. - In async path, prompt invocation will happen, send email alerts, and close case.
- In run immediately path, I check for a static boolean (let's say
runFlow) through Apex action, and continue only if itstrue. - LWC Apex will set
runFlowto true, and usingFlow.Interview.createInterview()andstart()I'll invoke my record triggered flow (run immediatepath) and pass thecase record Idas input variable. - The record triggered flow has all the logic of when to consider
triggering caseflow variable and when to consider thecase record Id from LWC. - Necessary checks are performed in the flow so that
run immediatelypath is not triggered when case is updated - Only Async path is triggered.
My questions:
- Is it a good practice/approach to have this design? I tested with a small flow that record-triggered flows can indeed be invoked using
Flow.Interview start()method. But I could only see documentations around invoking auto-launched flows from Apex. - My observation (and hence, assumption) from the test is that when Apex invokes flow like this, entry criteria is skipped (which is what I want when invoked from LWC Apex).
- The invocable Apex action to check
runFlowboolean returns aListof wrapper (as per the rules of InvocableMethods, List should be returned) with only one boolean property. But, from LWC only one record is passed at a time - So this shouldn't be an issue. - How reliable is the approach of having a flow which can run in bulkified way (the async path), and also a part of it which can be triggered to handle just one record.