1

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.

  • I have created a button in lightning component which calls lightning controller.Once that button is clicked,a create record page is displayed with pre populated field values.Is it possible to display a create record page with pre populated values as soon as lighting component i.e. without clicking button in lightning component – devsfdc Oct 17 '17 at 10:10
5

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

  • Yeah,it got saved! I am very new to lightning and not familiar with syntax.Thanks!! – devsfdc Oct 17 '17 at 7:58
  • JavaScript fails silently and is bit difficult to debug in lightning. But eventually it would get easy with time :) – Raul Oct 17 '17 at 8:08
  • I have created a button in lightning component which calls lightning controller.Once that button is clicked,a create record page is displayed with pre populated field values.Is it possible to display a create record page with pre populated values as soon as lighting component i.e. without clicking button in lightning component – devsfdc Oct 17 '17 at 10:11
  • Kindly post a new question for something new, otherwise it would be hard to follow when other people look at this having similar issue. – Raul Oct 17 '17 at 10:33
  • OKay..I am going to post a new question.Marking your answer as accepted – devsfdc Oct 17 '17 at 10:36

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.