0

I've created a visualforce page with an Apex controller and have a button that should open a Screen Flow but am unable to do so.

Here is the code that should call the flow:

public void openOpportunityFlow() {
        Map<String, Object> inputVariables = new Map<String, Object>();
        inputVariables.put('LeadId', selectedLeadId);

        String flowApiName = 'Open_Opp_Screen_Flow';

        Flow.Interview flowInterview = Flow.Interview.createInterview(flowApiName, inputVariables);

        flowInterview.start();
}

The error I'm getting is "Start can't be called on a flow with the process type Screen Flow."

I've done some searching online and am having trouble finding anyone else with the issue.

2 Answers 2

3

You cannot run a screen flow from Apex. You need to use a UI mechanism to launch them, such as lightning-flow for LWC.

In Apex there's no UI context - Apex is entirely backend - so the flow cannot execute (it has nowhere to show the screens). You can invoke auto-launched flows from Apex.

2
  • I understand that Apex is purely backend, but the page I'm building is a visualforce page so I would think I would be able to call and display that screen flow on the page. Thanks
    – Matt
    Commented Aug 1, 2023 at 17:13
  • Visualforce is Web 1.0 technology with a bit of AJAX added for some minor interactivity between browser and server. Apex called from Visualforce is only running on the backend and cannot launch a screen flow because it is not part of the UI. Yes, you call it from the UI, but it is not UI code. You must use the UI functionality such as the one I linked to to actually launch and render the flow.
    – Phil W
    Commented Aug 1, 2023 at 18:54
0

Unfortunately, you cannot "start" a screen flow as mentioned in this Apex Reference Guide

This method (start) can be used only with flows that have one of these types.

 - Autolaunched Flow
 - User Provisioning Flow

You must log in to answer this question.

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