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

force:inputField auto populated in Lightning component

1down votefavoriteI am trying to auto populated the force:inputfield but its not working, is there some specific way to populating as other types of field are working fine like picklist, text, date & checkbox

Here is the code
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="recordId" type="Id"/>
<aura:attribute name="account" type="Account" default="{ 'sobjectType': 'Account' }"/>
<!-- lookup to lead on account object -->
<force:inputField aura:id="accNe2" value="{!v.account.Lead__c}"/>

Here is the controller
doInit: function(component) {

    var action = component.get("c.getAccountFieldValues");
    action.setParams({ recordId : component.get("v.recordId") });
    action.setCallback(this, function(actionResult) {
        var infos = actionResult.getReturnValue();
        component.set("v.account", infos);             

And the apex method has normal SOQL returning account record.
Alain CabonAlain Cabon
Hello Abhi Tripathi,

It is a very interesting question indeed.
  • <force:inputField> is a Beta component (or even perhaps Alpha for me) if you compare with <apex:inputField>
You cannot autopopulate <force:inputField> for a lookup field from the controller (that works only with the default in the component, one value and just one   default="{ 'sobjectType': 'Account', Lead__c:'id value' }"/).  

I have looked for many months and I cannot find the solution (+ cases for the Salesforce support indeed and they have no solution with <force:inputField> currently). 
  • "other types of field are working fine like picklist" ??? try to populate with a picklist restricted by a record type and try to use dependant picklists like with <apex:inputfield> (or a rich text).
Officially documentation Winter 18 (v41) : Dependent picklists and rich text fields are not supported. Required fields are not enforced client-side.
  • In fact, Salesforce works on new components for .. the future:
Lightning Components Roadmap​:
 lightning:lookup + lightning:picklist: future.
  • Many people have developed their own lookup component.
One of the best development of lookup component I found is this Lookupcomponent, developed by Mr Sam Jungleeforce (Bengaluru / Bangalore)

Lookupcomponent: Use this lightning component in your project to enable users to select lookup record:

Many other components for lookup on Github (because the Salesforce component doesn't work): 

There is no example of a lookup field in the Lightning Components Developer Guide:

User-added image

Zero result.

User-added image

User-added image
<force:inputfield> is nearly nowhere in the documentation or the release notes (??).

Best regards
Hi Alain,

I am stuck with something similar. Actually I am trying to open a record create page on click of a button on the Account detail page in lightning. I have created a lightning component and a controller as follows.
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
 <aura:handler name="init" value="{!this}" action="{!c.doInit}" access="global"/>
doInit : function(component, event, helper) {

 var createnewRec = $A.get("e.force:createRecord"); 
"entityApiName": "Test_Object__c", 
"defaultFieldValues": { Name : 'Test Record1', 
                        Description__c :'test description',
                        ParentPicklist_field__c : 'a', 
                        ChildPicklist_Field__c : '1' } });; 

The dependent picklist isn't getting populated. Here ChildPicklist_Field__c is the dependent picklist for the ParentPicklist_field__c .The values will be fetched dynamically from an apex class.  Any thoughts on this ??

@Shweta - similar issue for me - submitted Idea: