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
Surinder Singh 51Surinder Singh 51 

force:createrecord not working

JS Controller :   method calling from Comp button.
 
createContact: function(component, event, helper){ //
         
         var createRecordEvent = $A.get('e.force:createRecord');
      
            createRecordEvent.setParams({
                'entityApiName': 'Contact',
                "defaultFieldValues": {
                    'Phone' : '415-240-6590'}
            });
            createRecordEvent.fire();
        
    }

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



Requirmeent: on click of button, want to display create contact screen with default phone or any field.
Best Answer chosen by Surinder Singh 51
Danish HodaDanish Hoda
Hi Surinder,
I too faced the same error, I mitigated the issue by navigating to the record-create form.
Please refer the link (https://developer.salesforce.com/docs/component-library/bundle/force:createRecord/documentation) for better insights.

All Answers

Danish HodaDanish Hoda
Hi Surinder,
I too faced the same error, I mitigated the issue by navigating to the record-create form.
Please refer the link (https://developer.salesforce.com/docs/component-library/bundle/force:createRecord/documentation) for better insights.
This was selected as the best answer
Surinder Singh 51Surinder Singh 51
Hi Danish,

Are you talking about lightning:navigate ?  Does it means force:createrecord has bugs and not working for all ? 

If possible can you please share your lines of code.... how to use record-create-form.
Surinder Singh 51Surinder Singh 51
I created a new component using lightning :recordForm:

From my button click  i tried to navigate to new component again, getting nothing : 

var newEvent= $A.get("e.force:navigateToComponent");
        newEvent.setParams({
            componentDef: "RecordCreateEditForm",
            componentAttributes: {
                //Set you attributes here if required.
            }
        });
Surinder Singh 51Surinder Singh 51
Danish it got worked. It was a small miss. Navigating to recordform comp is working fine. Thanks