3

Is there a way to use force:createRecord but capture the redirect to the newly created record page that occurs after saving the record? Finally, prevent the redirect from completing?

createRecord : function (component) {
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Event__c"
    });
    createRecordEvent.fire();
} 
  • I had the same question - it does not seem to have a solution, so I think this is not possible – Itai Shmida Nov 12 '17 at 11:11
6

So instead of hacking the redirect with window.location.hash, you can use the following navigation method in the "panelOnDestroyCallback".

"panelOnDestroyCallback": function(event) {
                $A.get("e.force:navigateToSObject").setParams({
                    recordId: component.get("v.recordId"),
                    slideDevName: "detail"
                }).fire();
            }

The page will navigate to the new record and then back so it is not the smoothest transition but it does work.

EDIT

Just add "navigationLocation": "RELATED_LIST" to the list of params and you will stay on the page after saving.

| improve this answer | |
5

There is an undocumented solution for this. Below is the js controller function that creates a new Contact record and redirects back from the record page to the initial page after a new record is created.

createNewContact: function(component, event, helper) {
    var windowHash = window.location.hash;
    var createEvent = $A.get("e.force:createRecord");
    createEvent.setParams({
        "entityApiName": "Contact",
        "panelOnDestroyCallback": function(event) {
            window.location.hash = windowHash;
        }
    });
    createEvent.fire();
}

Where "panelOnDestroyCallback" is the hidden force:createRecord attribute. I know that's an ugly hack, but hey, if I had known this before I wouldn't have spent 50+ hours implementing a fully-custom multi-object 'createRecord' component with all the schema tricks, custom lookups, multipicklists etc.

| improve this answer | |
  • There are chances that this won't redirect sometime. – itzmukeshy7 Jan 4 '18 at 15:35
  • 1
    you're right, but that's always the story with SF... people find the way to make work under the risk of some future issues (e.g. Visualforce URL hacks which are unrecommended and not supported while still very useful) – DMITRY KRYVYI Jan 4 '18 at 16:08
  • 1
    Does this solution even work? It didn't on my Community page where I have my custom component. It still redirects me to the new record's detail page. MEH! – Arnold Jr. Jan 26 '18 at 19:52
2

I answered in the other thread, but to make it easier answering here too:

So far it's not possible.

If you have access to the Partner Community, I asked about this here but it was not on the roadmap for now.

An idea has been created recently for it, so I would suggest to go and vote for it here.

| improve this answer | |

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