[SalesForce] How to redirect to URL from flow with invocable apex

I have a flow from which I want to call a visualforcepage with some parameteres in the URL. The flow calls the invocable apex and the pagereference method but does not redirect to the url but does show the Screen test4 in the flow. What am I missing since I do not get redirected to an external URL. Why is the redirect method triggered but does not navigate to the given URL. I also do not have any exceptions.

Apex

public with sharing class  NavigateToUrl {

    //input details that comes to apex from flow
    public class InputParameters {

        @InvocableVariable
        public Case CaseRec;

        @InvocableVariable
        public Zuora__Subscription__c SubRec;

    }
    //output details which goes from apex to flow
    public class OutParameters {

        @InvocableVariable
        public String Test1;

        @InvocableVariable
        public String Test2;
    }

    @InvocableMethod(label = 'Navigate to URL' description = 'Navigate to URL')
    public static void getInputParams(List<InputParameters> InParam) {
        system.debug('Flow Invoked');
        redirect(InParam[0].CaseRec.AccountId, InParam[0].CaseRec.id, InParam[0].CaseRec.ContactId, InParam[0].SubRec);
    }

    public static PageReference redirect(id AccountId, id CaseId, id Contactid, Zuora__Subscription__c Sub) {
        system.debug('redirect started');
        String baseUrl = string.valueOf(URL.getSalesforceBaseUrl());
        String gotoUrl = baseUrl + 'apex/' + 'shop?accountid=' + AccountId + '&caseid=' + CaseId + '&contactid=' + ContactId + '&subrec=' + Sub;
        PageReference newUrl = new PageReference(gotoUrl);
        newUrl.setRedirect(true);
        return newUrl;
    }
}

Flow

Result screen component
enter image description here

Best Answer

If I understand correctly, the user experience will be the as soon as the user selects a radio button and click next he has to be navigated to the URL. If this is right then we do not need the Local Action but a Screen element built using a custom Aura Component that uses lightning:availableForFlowScreens.

In the example below I show Account as a selectable radio option in Screen 1 and then open the details page of the selected Account in Screen 2. Details below

Flow Screen 1 Screen 2- NavigatetoUrl Component

Design Attribute

js Controller ({invoke : function(component, event, helper) { // Get the record ID attribute var record = component.get("v.recordId"); var aUrl = "/"+record;

var urlEvent = $A.get("e.force:navigateToURL"); urlEvent.setParams({ "isredirect": "true", "url": aUrl }); urlEvent.fire(); }})

Related Topic