function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swarnalata MaruvadSwarnalata Maruvad 

Lighting Component not returning to calling Flow

Hi,
I have a flow as an action on an SObject. This flow creates a child record for this record on another SObject with values prefilled from the calling record. Once this record is created, I need to display it in edit mode for user to enter more required fields. If user enters these and clicks 'Save' the record is saved. However, if the user clicks 'Cancel' the record created in flow needs to be delete.

I used Lightning component for displaying created record in edit mode, force:editRecord and I am trying to set a variable based on whether the user saves the record or cancels it. Based on this value which I am accessing in the Flow, I am either displaying a 'Saved' screen or deleting the created record and displaying a 'Cancelled' screen.

I am new to this and  have coded based on various examples I found online.

However, when executing, once the record is displayed for editing and the user either saves or cancels, control is not returning to the Flow. I am taken back to the original record which called the flow. Thus I am not able to delete the child record that was created in Flow when user chooses 'Cancel' Below is my code. I don't know what am I missing. Any help is most appreciated. Thanks!

Component
<aura:component implements="force:lightningQuickAction,lightning:availableForFlowActions" access="global">
    <aura:attribute name="recordId" type="string"/>
    <aura:attribute name="saveState" type="string" default="UNSAVED"/>
    <aura:handler name="onSaveSuccess" event="force:recordSaveSuccess" action="{!c.handleSaveSuccess}"/>
     <ui:button label="Save" press="{!c.save}"/>
    <ui:button label="Cancel" press="!c.cancel}"/>
</aura:component>

Controller
    invoke : function(component, event, helper) {
        //Get the record ID attribute
        var record = component.get("v.recordId");
        
        //Get the Lightning event that opens a record in new tab
        var redirect = $A.get("e.force:editRecord");
        
        //Pass the record ID to the event
        redirect.setParams({
            "recordId": record
        });
        //Open the record
       
        redirect.fire();
        
    },
    
    save : function(cmp, event, helper){
        //save the record
        component.find("edit").get("e.recordSave").fire();
        
    },
 
     handleSaveSuccess : function(cmp, event, helper){
        //Gets called once save is done 
        cmp.set("v.saveState","SAVED" );

    },
        
    cancel : function(cmp, event, helper){
        cmp.set("v.saveState", "CANCELLED") ;
    }
})