2

I am trying to auto populated a lookup field using 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

Component

<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);             
    });
    $A.enqueueAction(action);
},

And the apex method has normal SOQL returning account record.

  • This looks fine. What exactly does not work? What type is the Lead__c field? – Itai Shmida Aug 27 '17 at 5:10
1

My assumption is that Lead__c is of type "Lookup" even if you did not explicitly stated so.

Now I can see two possible reasons:

  • force:inputField may be still buggy with Lookup-fields. There where so many bugs in the past with force:inputField in general and Lookups in particular that I wouldn't wonder.
  • if you hold in your Lead__c an relation to the lead out of which the Account has been converted (fishing in the dark, this is again only an assumption since your questions isn't clear on that) the fact that the lookup points to an converted lead might be the reason. Converted leads behave differently in many ways.

To narrow it down you should state your field type. If field type is Lookup, try to create another test-lookup field on Account e.g. looking up contacts and test-populate it on your test record using the standard UI to ensure it is populated correctly. Now change your compo for testing to this new lookup field instead of Lead__c. If this still doesn't work I think it's a bug in force:inputField

| improve this answer | |
  • Thanks Uwe, modified the query according specified that issue is in only lookup field. But its not because of the Lead object only, I've tried using a custom object as well, but force:input field doesn't support lookup auto-population. – Abhi Tripathi Aug 27 '17 at 17:39

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.