3

I'm trying to use force:createRecord and it works okay in Lightning Experience, and S1 but but I get the following error message when I am using a stand alone app. If I preview the "sampleCreateRecordApp.app" I get the below error message:

"This page has an error. You might just need to refresh it. Action failed: c:sampleCreateRecord$controller$createRecord [Cannot read property 'setParams' of undefined] Failing descriptor: {c:sampleCreateRecord$controller$createRecord}"

Below is the simple compoment I'm trying to get to work in a stand alone app (or lightning out). The documentation link here alludes that they can be used outside of LEX or S1

If I try to extend the application with extends="ltng:outApp" the application does not render at all. Any advice would be great. Thanks!

sampleLightningOutPage.page

<apex:page >


    <script src="/lightning/lightning.out.js" />
    <div id="sampleComponentDiv" />    

    <script> 
        $Lightning.use("c:sampleCreateRecordApp",function() {
            $Lightning.createComponent(
                "c:sampleCreateRecord",
                {},
                "sampleComponentDiv"
            );

        });
    </script>
</apex:page>

sampleCreateRecordApp.app

<aura:application >
    <c:sampleCreateRecord/>

</aura:application>

sampleCreateRecord.cmp

 <aura:component implements="flexipage:availableForAllPageTypes">
    <lightning:button variant="brand" label="Submit" onclick="{! c.createRecord }" />


</aura:component>

sampleCreateRecord.js

({
    createRecord : function (component, event, helper) {
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "Contact"
        });
        createRecordEvent.fire();
    }
})
  • can you share your visualforce page code also? – Itai Shmida Feb 23 '17 at 5:52
  • I updated my post to include the visualforce page as well. Thanks for your help in advance! – jojopogi Feb 23 '17 at 18:31
3

The force:createRecord feature is unsupported for ligtning out - as stated in the documentation:

This event is handled by the one.app container. It’s supported in Lightning Experience, the Salesforce app, and Lightning communities.

That means - not available on lightning out and therefore inside a visualforce page.

  • The documentation link you provided is not working. Can you please share the link again – Monalisa Das Jun 29 '18 at 2:04
  • @MonalisaDas updated! – Itai Shmida Feb 5 at 13:10
  • wre you able to do it with any work arounds ? – ScoRpion Apr 22 at 13:22
0

@Monalisa Das

You can find the updated documentation here - force:createRecord Documentation

Your Answer

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

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