handleCreateRecord : function(component, event, helper) {
let currentUrl = decodeURIComponent(window.location.search.substring(1));
let createRecordEvent = $A.get("e.force:createRecord");
var accountId = component.get('v.accountId');
alert(currentUrl);
createRecordEvent.setParams({
"entityApiName": "Lead",
"defaultFieldValues": {
"Account__c" : accountId,
"RecordTypeId": "0121l000000566UAAQ"
},
"panelOnDestroyCallback":function(event) {
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": "0011l000006pDoxAAE",
"isredirect":true
});
// navigate back to account only if Lead create was cancelled
decodeURIComponent(window.location.search.substring(1)) == currentUrl ? navEvt.fire() : console.log('nav to Lead');
}
});
createRecordEvent.fire();
}
Okay, So..I am trying to make the user go back to the account page upon hitting the cancel in this new creation of my custom object but it is not working. May I know what's wrong here ?
Best Answer
As of API v43, the suggested method for navigation is using
lightning:navigation
and you can see examples in the documentation here. Note that it leverages thePageReference
object and you should usestandard_recordPage
type in this situation.Also, Lightning Locker wraps the original
window
and makes it a SecureWindow. As per the documentation here, it looks likelocation
has different behavior than the standard window.location that you're used to.Last, you can try the Lightning Console with sample code, inspect in the JS console and see what values it gives you.