[SalesForce] Parsing error: Unexpected token “defaultFieldValues” in Lightining controller

I am trying to prepopulate a field on record creation.For this,I have created Lightning component and a controller.

Lightning component code:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <lightning:button label="Create an application" 
        onclick="{!c.createRecord}" />
</aura:component>

Controller:

({
   createRecord: function(component, event, helper) {
      var createRecordEvent = $A.get("e.force:createRecord");
      createRecordEvent.setParams({
         "entityApiName": "Application__c" 
          "defaultFieldValues": {
        'Name' : 'System Number',
        }
      });
      createRecordEvent.fire();
   }
})

But on saving controller,it throws the error:

Failed to save CreateapplicationrecordController.js: ESLINT_ERROR: {c:Createapplicationrecord – CONTROLLER} line:col [6:11] –> Parsing error: Unexpected token "defaultFieldValues" : Source

Name in defaultfieldvales is the API name of a standard field labelled as Number. Data type is Text.

Please help with this error.

Best Answer

You missed a comma and had an extra one:

({
    createRecord: function(component, event, helper) {
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "Application__c",
            // was missing in above line, so added one
            "defaultFieldValues": {
                'Name' : 'System Number'
                // removed comma from above line
            }
        });
        createRecordEvent.fire();
    }
})

enter image description here

Related Topic