Lightning App: NewOppLEXApp

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

Lighting Component: OpportunityLEX

<aura:component controller="abc" implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,flexipage:availableForRecordHome" access="global">
<aura:attribute name="recordId" type="Id"/>
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<aura:attribute name="newRec" type="controller"/>
<lightning:notificationsLibrary aura:id="notifLib" /></aura:component>


    init : function(component, event, helper) {
        var objId = component.get("v.recordId");
        var action = component.get("c.method");
            "recId" : objId
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.newRec", response.getReturnValue());
                    var recordTypeId = component.get("v.newRec.recordType");
                    var returnURL = component.get("v.newRec.returnURL");
                    var entity = component.get("v.newRec.entity");                    
                    var createRecordEvent = $A.get('e.force:createRecord');
                    if (createRecordEvent) {
                            "entityApiName" : entity,
                            "recordTypeId" : recordTypeId,
                            "defaultFieldValues" : {                           
                                "AccountId" : objId,

VF Page:

<apex:page standardController="Opportunity" extensions="Controller" lightningStylesheets="true"> 
    <apex:includeLightning />    
    <apex:includeScript value="/lightning/lightning.out.js" />

        <div id="divId" />
            var accId = "{!$CurrentPage.parameters.accId}";
            $Lightning.use("c:NewOppLEXApp", function() {
                                           { "recordId": accId},
                                           function(cmp) {
                                               console.log('Test before URL');

When I run this VF Page, e.force:createRecord fires. However I am right now seeing a blank window as "SetCallback" shows after "Test before URL", hence createrecord event doesn't pops up(what I believe). Please let me know if I am missing something in order to call createrecord event through vf page.

  • What about the other console.log statements inside the IF block in the callback? Did you get correct response? – arut Sep 21 '20 at 14:39
  • yes it did get the correct response – sfdc rowdy Sep 22 '20 at 5:27

It did fire; if you saw SetCallback in the console, this means the code did execute, so the event did fire. If you need the callback to execute after the event is fired, you need to make it a delayed call, which you can do with setTimeout.

function(cmp) {
    setTimeout( () => { console.log('Test before URL') });

However, it's not clear that this will help you solve your problem. Please read about the X-Y Problem.

  • sorry my bad, yes it did fire but after "Test before URL" , due to which createrecord event pop up doesn't show up , right now it is showing me a blank window. May be my understanding is not correct. Please help. – sfdc rowdy Sep 22 '20 at 5:26
  • Seems like a limitation of using force:createRecord through VF Page as it outside of LEX/SF1 and also cannot use {!URLFOR($Action.Opportunity.New)} as it is declared to be a bug, Possible solution will be using create your own custom event handler. – sfdc rowdy Sep 22 '20 at 7:13
  • I checked at my end createRecordEvent is undefined due to which it is not going further. – sfdc rowdy Sep 22 '20 at 7:15

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.