0

I think that I am missing something small or then my whole logic is wrong with this. Here is the Lightning Component, that has been copied from a Salesforce Developer sites. https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_flow_cmp.htm

COMPONENT:

<aura:component implements="lightning:actionOverride,force:lightningQuickAction,force:hasRecordId,lightning:availableForFlowActions,lightning:availableForFlowScreens" access="global">
  <aura:attribute name="AccountID" type="String" />
  <aura:handler name="init" value="{!this}" action="{!c.init}" />
  <div class="slds-box slds-theme_default slds-theme_backgroundColor-lightblue">
     <lightning:flow aura:id="flowData" onstatuschange="{!c.handleStatusChange}"/>
  </div>
</aura:component>

CONTROLLER:

({
    init : function (component) {
        // Find the component whose aura:id is "flowData"
        var flow = component.find("flowData");
        // In that component, start your flow. Reference the flow's API Name.
        flow.startFlow("Account_Override");
    },
    handleStatusChange : function (component, event) {
        if(event.getParam("status") === "FINISHED") {
            var outputVariables = event.getParam("outputVariables");
            var outputVar;
            for (var i = 0; i < outputVariables.length; i++) {
                outputVar = outputVariables[i];
                if (outputVar.name === "redirect") {
                    var urlEvent = $A.get("e.force:navigateToSObject");
                    urlEvent.setParams({
                        "AccountID": outputVar.value,
                        "isredirect": "true"
                    });
                    urlEvent.fire();
                }
            }
        }
    }
})
0

I believe force:navigateToSObject is deprecated. You would want to use the lighting navigation service instead. Here's a demo of how the component would look alike,

<aura:component implements="lightning:availableForFlowActions">
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="sObject" type="String" />
    <aura:attribute name="mode" type="String" default="view" />
    <lightning:navigation aura:id="navService" />
</aura:component>

------------JS-----------------------

({
  invoke: function (component, event, helper) {
    var navService = component.find("navService");
    var recordId = component.get("v.recordId");
    var objectName = component.get("v.sObject");
    var mode = component.get("v.mode").toLowerCase();
    // Open the Record page in View mode first so that it persists after the Edit Modal closes
    var pageReference = {
      type: "standard__recordPage",
      attributes: {
        recordId: recordId,
        objectApiName: objectName,
        actionName: "view"
      }
    };
    navService.navigate(pageReference);

    if (mode == "edit") {
      var pageReference = {
        type: "standard__recordPage",
        attributes: {
          recordId: recordId,
          objectApiName: objectName,
          actionName: mode
        }
      };
      navService.navigate(pageReference);
    }
  }
});
1
  • 1
    Hi, thank you for the demo, I will try it out. Thank you also pointing out that force:navigateToSObject is deprecated, should've noticed that. Also apologies for the wrong indentation with the question. – Henri Harvilahti Dec 8 '20 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.