I am not an expert at javascript / lightning, but trying my hands on this

How should I handle the force:createrecord event? All I want to do is redirect back to the component tab after the record is saved. In visualforce on save I can specify a saveurl and cancelurl, can I do something like that in lightning

I tried to use pagereference method with @AuraEnabled but I get

"Return type does not support AuraEnabled"

There must be some way to return the save back to the component view which I am missing.


<aura:component implements="force:appHostable" controller="ContactListController">
    <aura:attribute name="contactlist" type="rao6308.contact[]"/>
    <aura:handler event="force:createRecord" action="{!c.handlecreateEvent}"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
        <ui:inputSelect label="Select me: " class="dynamic" aura:id="picklistval"/>

        <ui:button aura:id="button" label="Click me" press="{!c.createRecord}"/>

Client side controller: I assumed handlecreateEvent would navigate me back to my component on save, but it is not redirecting me back, how would I redirect the view back to my component?

    doInit : function(component, event) {
                var opts = [
        { "class": "optionClass", label: "Account", value: "Account", selected: "true"},
        { "class": "optionClass", label: "Contact", value: "Contact" },
        { "class": "optionClass", label: "Lead", value: "Lead" }
        component.find("picklistval").set("v.options", opts);

    createRecord : function (component, event, helper) {
    var createRecordEvent = $A.get("e.force:createRecord");
    var picklistselection = component.find("picklistval");
            "entityApiName": picklistselection.get("v.value")
   handlecreateEvent : function(component, event) {
        var evnt = $A.get("e.force:navigateToComponent");

Thanks for the help in advance.

  • Is that a direct copy/paste? I'm pretty sure component namespace is a lowercase c. You appear to have an uppercase C for C:bootstrappage. – pchittum Oct 14 '15 at 19:30
  • @Peter the capital C was a typo – Meg Oct 14 '15 at 20:46
  • Can someone please help me on this :(, not sure if this is even possible with lightning – Meg Oct 15 '15 at 15:48
  • well...one thing is you never actually call evnt.fire() on e.force:navigateToComponent. And you are right, PageReference methods are not supported in Lightning Components at all. Have you tried going through the trailhead trail with Lightning Components? It is a very easy way to get your hands dirty and understand better how LCF works. – pchittum Oct 15 '15 at 16:51
  • 1
    That's not entirely true. Lightning Components is a web component framework. It is designed for any web UI. Although the first way we used it was the Salesforce1 mobile app. We are now using it for the desktop Lightning Experience app going GA as we speak in Winter 16. A better way to put it is this: it is a modern web framework. It supports mobile as well as any modern web framework does. – pchittum Oct 15 '15 at 20:28

Your Answer

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

Browse other questions tagged or ask your own question.