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
Lek LextechLek Lextech 

Create record with default value in lightning component

Hi All,

I try to pass variable for relationship field (relationshipField ) to be default value parameter to create record, but it doesn't work, no default value appear in create record panel (it works when I fix field name instead). Please help.

------------------Component Attribute-------------------------
<aura:component controller="DataTableController" access="public" implements="force:appHostable,flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes,force:hasRecordId">
<aura:attribute access="public" name="object" type="String" default="Account" required="true"/>
<aura:attribute access="public" name="columnfields" type="String" required="true" default="Id, Name"/>
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="remoteRecordId" type="Id" />
<aura:attribute name="relationshipField" type="String" />

<lightning:button variant="brand" label="New" iconName="utility:home" iconPosition="right" onclick="{!c.creatRecord}" />

----------------------JS Controller----------------------------------------
creatRecord : function (component, event, helper) {
    var sObject = component.get("v.object");
    var relationshipField = component.get("v.relationshipField");
    var parentID =  component.get("v.recordId");
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": sObject,
        "defaultFieldValues": {
            relationshipField : parentID,
            }
        });
    createRecordEvent.fire();
    }

creatRecord : function (component, event, helper) {
    var sObject = component.get("v.object");
    var relationshipField = component.get("v.relationshipField");
    var parentID =  component.get("v.recordId");
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": sObject,
        "defaultFieldValues": {
            relationshipField : parentID,
            }
        });
    createRecordEvent.fire();
    }
MagulanDuraipandianMagulanDuraipandian
Check this - http://www.infallibletechie.com/2018/03/lightningdatatable-in-salesforce.html