0

Can we add logic for redirection on the click of cancel button in the below code

createRecord : function (component, event, helper) {
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Contact"
    });
    createRecordEvent.fire();
} 
2
  • Can you elaborate the question more? Is like when you click on Cancel the Contact should be created and the Cancel event on whatever form you are, should also get fired? Mar 16, 2022 at 8:04
  • When i click cancel , i want to redirect to some custom page and contact shouldn't be created. Mar 16, 2022 at 8:09

1 Answer 1

0

We can not handle the cancel button for the standard create record component, but there is a work around, details below

  1. We use direct redirection in lightning for new record creation via url

  2. set the default values for new record in the url itself

  3. set the background context in url to make sure that for user the background page is not empty when he see a new record popup

  4. I had done it with following piece of code to make sure when we create new quote user will get redirected to existing opportunity on cancel

            var navigateToURL;
            navigateToURL = "/lightning/o/SBQQ__Quote__c/new?&defaultFieldValues=SBQQ__Opportunity2__c="+component.get("v.parentRecordId")+",SBQQ__Account__c="+component.get("v.accId")+"&backgroundContext=%2Flightning%2Fr%2FOpportunity%2F"+component.get("v.parentRecordId")+"%2Fview"+"&nooverride=1";
            var urlEvent = $A.get("e.force:navigateToURL");
            urlEvent.setParams({
                "url": navigateToURL
            });
            urlEvent.fire();   
            $A.get("e.force:closeQuickAction").fire();
    
2
  • urlEvent.fire() will open the create record page through the url but which code is changing the behaviour of cancel button. Mar 16, 2022 at 7:56
  • this attribute in url "&backgroundContext=%2Flightning%2Fr%2FOpportunity%2F" Mar 16, 2022 at 7:58

You must log in to answer this question.

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