0

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 whether Boolean__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 its true.
  • LWC Apex will set runFlow to true, and using Flow.Interview.createInterview() and start() I'll invoke my record triggered flow (run immediate path) and pass the case record Id as input variable.
  • The record triggered flow has all the logic of when to consider triggering case flow variable and when to consider the case record Id from LWC.
  • Necessary checks are performed in the flow so that run immediately path 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 runFlow boolean returns a List of 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.
1
  • I would not do this -- instead, create two flows (immediate+async; immediate) and a common subflow for the non-async logic. Avoid passing caller-specific context variables that control execution of a flow. Commented Jul 24 at 23:33

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.