Lightning : Issue while calling createRecord Event Component

I am trying to embed a lightning component inside a visualforce page –

MytestVFPage visualforce page-

<apex:outputPanel >
       <div id="lightning" />
            $Lightning.use("c:createAccountGlobalApp", function() {     
                                       function(component) {});


**createAccountGlobalApp** container -

<aura:application access="GLOBAL" extends="ltng:outApp"> 
    <aura:dependency resource="c:CreateAccount"/>

**createAccount** component -
<aura:component >
    <div class = "container">
        <ui:button label="Lightning button" press="{!c.createAccountButton}">    </ui:button>

createAccountController.js controller

    createAccountButton : function(component, event, helper) {

createAccountHelper.js helper-

    createRecord:function(component) {
            var createRecordEvent = $A.get("e.force:createRecord");
            "entityApiName": "Account"


When I click on the UI button inside visualforce page it throws an error –

“Something has gone wrong. Action failed: c$CreateAccount$controller$createAccountButton [TypeError: Cannot read property ‘setParams’ of undefined] Failing descriptor: {c$CreateAccount$controller$createAccountButton}. Please try again.

Can you please help what is wrong here?


I’m afraid you cannot use force:createRecord outside of LEX/SF1, below is the note from the doc.

force:createRecord event is handled by the 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, create
and wire up an event handler of your own.

Looks like you have to build an custom component to get the account details input and create it.

Source : Link , Question Author : Hitesh , Answer Author : Praveen

Leave a Comment