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
NerdyNerdy 

Pre-fill a field in lightning component with value entered in salesforce

Helloo, 

Can you help me to achieve this requirement ?

How can I pre-fill a field in a lightning form with value entered in salesforce (Account object)
      <lightning:input name ="myField "value="{!v.account.myField}"  />

 
Raj VakatiRaj Vakati
Create an attribute with the Default value and call it
 
<aura:attribute name="myField" type="String" default="hello"/>

Here is the way
 
<lightning:input name="input8" value="{! v.myField}" placeholder="type your first name..." label="Text field with attribute binding" />



If you want to populate from the apex class .. call the apex class method on do Inti and set the value to attribute 
 
Naveen KNNaveen KN
Yah adding to Raj, you can  make use of Lightning Data Service to show the field value on the UI without writing a server side code. 
rambabu nrambabu n
Hi Nerdy,

You can provide default values for standard or custom object like below.
For account:
<aura:attribute name="account" type="Account" default="{'sobjectType':'Account', 'myField':'Account123'}"/>

You must provide sobjectType in default.
Here sobjectType is case sensitive. If you use sObjectType it will not work.

Then if you use below code you will get default value.
<lightning:input name ="myField "value="{!v.account.myField}"  />

Custom object:
<aura:attribute name="cusobj" type="'customobject__c" default="{'sobjectType':'customobject__c', 'field1':'value1','field2':'value2'}"/>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks.
Rambabu.