function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kalpesh Vyas 14Kalpesh Vyas 14 

force:createRecord is not working

Hello,

I am getting below error while trying to use force:createRecord in one of my lightning component
User-added image

Here is little code excerpt where xQualification_Comment__c is custom object.
Below is js for component:
User-added image
Here is component 
User-added image
Best Answer chosen by Kalpesh Vyas 14
Nayana KNayana K
When you try to launch the component via app (testApp in your case) in the developer console  , standard events (createRecord, showToast,  navigateToSobject,  etc)  will be undefined. 

var createRecordEvent = $A.get("e.force:createRecord");


createRecordEvent will have "undefined " always. 

Therefore launch your commentsViewComponent in LEX via app builder or lightning quickaction or drag to detail page to check how it works.

All Answers

Nayana KNayana K
When you try to launch the component via app (testApp in your case) in the developer console  , standard events (createRecord, showToast,  navigateToSobject,  etc)  will be undefined. 

var createRecordEvent = $A.get("e.force:createRecord");


createRecordEvent will have "undefined " always. 

Therefore launch your commentsViewComponent in LEX via app builder or lightning quickaction or drag to detail page to check how it works.
This was selected as the best answer
Kalpesh Vyas 14Kalpesh Vyas 14
Thanks it worked!!
Kalpesh Vyas 14Kalpesh Vyas 14
Hi Nayana K,
I seen this standard behavior takes me to object which is recently created after I click on save, is it something possible or avaiable to prevent this behavior of redirection and stay on the detail page (the page which opened this window) after save?
Nayana KNayana K
No, we can't prevent this default behaviour unfortunately :(
Pavan Kumar PPavan Kumar P
Hi,

force:createRecord event is not working when I click the "Create Record" button. Please find the code below:

CreateRecordEvent.cmp:
<aura:component implements="flexiPage:availableforAllPagetypes,force:appHostable">
     
        <lightning:button label="Create Record" value="{!c.CreateRecord}" variant="brand"/>
   
</aura:component>

CreateRecordEventController.js:

({

    CreateRecord : function(component, event, helper) {
        var createRecordEvent = $A.get("e.force:createRecord");
       
        createRecordEvent.setParams({
            'entityApiName':'Account',
             });
        createRecordEvent.fire();
                }
})

Please help.
sravan n 3sravan n 3
Hi Nayana,
can we pass dynamic values instead of hard coded values in default fields like below,

"defaultFieldValues": {
                                    Opportunity__c' : OppID.AccountId
                                }
Any one please suggest if you have faced this so far.

Thanks,
Sravan