1

I am using standard force:createRecord to create Account. but I dont get create window when I clcik on a button. I am hosting this lightning app from a VF page (as I want to overide standard button). I have written handler for createRecord event.

But when I host this lightning component from left navigation panel then it works. Please advise what am I missing?.

VF Page :

<apex:includeLightning />

<script>
    $Lightning.use("c:TestClientCreationApp", function() {
      $Lightning.createComponent("c:TestClientCreation",
      { },
      "lightning",
      function(cmp) {
        // do some stuff
      });
    });
</script>

Lightning App : c:TestClientCreationApp

<ltng:require styles="/resource/SLDS201/assets/styles/salesforce-lightning-design-system-ltng.css" />
 <ltng:require styles="/resource/SLDS201/assets/styles/salesforce-lightning-design-system-vf.min.css" />

<aura:dependency resource="c:TestClientCreation"/>

Lightning Component : TestClientCreation

 <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

 <ui:button class="slds-button slds-button--brand" aura:id="btnCreateClient" press="{!c.showCreateClientModal}" label="">Create New Client </ui:button> 

TestClientCreation Js Controller :

showCreateClientModal : function (component, event, helper) {

    var createRecordEvent = $A.get("e.force:createRecord");
     createRecordEvent.setParams({
        "entityApiName": "Account"
    });
    createRecordEvent.fire();

},

createClient : function (component, event, helper) {

console.log('Yay');

}

1 Answer 1

1

Since you are now outside the Lightning component ,the force events will no more work .

Hence if you are using this in lightning experience ,then there is a trick to use sforce instead of force events .

you should be able to use sforce record create

createClient : function (component, event, helper) {

   console.log('Yay');
   sforce.one.createRecord(Account);
}
3
  • Thanks for your reply Mohith, but salesforce said we need to write a handler to use, which I have written. "This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce1 only. If used outside of Lightning Experience or Salesforce1, this event won’t be handled automatically. To use this event outside of one.app, create and wire up an event handler of your own." developer.salesforce.com/docs/atlas.en-us.lightning.meta/…
    – Ram
    Commented Aug 12, 2016 at 8:49
  • 1
    Also, sforce.one.createRecord(Account); will not prompt a window for user entering inputs right?. I need the standard create popup on firing this event
    – Ram
    Commented Aug 12, 2016 at 8:52
  • Have you tried my and? Also as per doc I have not had any success with my own event . Commented Aug 12, 2016 at 10:54

You must log in to answer this question.

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