I have to pre populate few lookup feilds when clicked on Button in my Component, The fields are getting populated if i specified static, And after click on my i'm showing a form in popup, Popup displaying with lookup fields un populated.Below are all the source code files. Any help is appreciated.


    <aura:attribute name="newDep" type="Deposit__c"
default="{ 'sobjectType': 'Deposit__c',
         'Connection__c': '',
         'Quote__c': '',
         'Contact__c': '0034C0000056UdqQAE',
         'Name': '',
         'Status__c': '',
         'Date__c': '',
         'Amount__c': '', 


        <div class="slds-page-header--vertical">
      <div class="slds-grid slds-grid--vertical">
             <ui:button label="New Deposite"  press="{!c.CreateNewDep}"/>

 <!-- popup related content -->
<div aura:id="modaldialog" aria-hidden="true" role="dialog" tabindex="-1" aria-labelledby="header43" class="slds-modal slds-fade-in-hide">
  <div class="slds-modal__container">
    <div class="slds-modal__header">

      <h2 id="header43" class="slds-text-heading--medium">Create Deposit</h2>
    <div class="slds-modal__content slds-p-around--medium">
<form role="form" class="slds-form--stacked slds-grid slds-wrap slds-grid--pull-padded slds-m-top--large">
<div class="slds-p-horizontal--small slds-size--1-of-1 slds-medium-size--1-of-2">
           <div class="slds-form-element">
                <label class="slds-form-element__label">Connection</label>
                <div class="slds-form-element__control">
                    <force:inputField aura:id="firstName" class="slds-input" value="{!v.newDep.Connection__c}" />
            <div class="slds-form-element">
                <label class="slds-form-element__label">Quote</label>
                <div class="slds-form-element__control">
                    <force:inputField aura:id="lastName" class="slds-input" value="{!v.newDep.Quote__c}" />
            </div> </div>
<div aura:id="backdrop" class="slds-backdrop slds-backdrop--hide"></div>   

ClientSide Controler :

    CreateNewDep : function(component, event, helper) {
         var action = component.get("c.getDepositeInstance");

    action.setParams({ "sObjId" : component.get('v.recordId')});
    action.setCallback(this, function(a) {
        if (a.getState() === "SUCCESS") {
            $A.log("Success!!!", a);
            console.log('--return value---');
            component.set("v.newDep", a.getReturnValue());

                var rec = component.get("v.newDep");
                rec.Connection__c = '0064C000002zrz4QAA';
                rec.Contact__c = '0014C00000643pZQAQ';
                rec.Quote__c = 'a0l4C000000UuOKQA0';
                rec.Status__c = '';
                rec.Date__c = '';
                rec.Amount__c = '';
                rec.name = '';
} else if (a.getState() === "ERROR") {
$A.log("Errors", a.getError());


                          //Toggle CSS styles for opening Modal



Apex class:

public class CreateNewDepositeCon {

@AuraEnabled public static Deposit__c getDepositeInstance(string sObjId){

opportunity Opty = [select id,AccountId,Quote__c from opportunity where id=:sObjId limit 1];

        Deposit__c tempDep = new Deposit__c();
        tempDep.Connection__c = Opty.id;
        tempDep.Quote__c = Opty.Quote__c;
        return tempDep;


If Id specified static:

It is populating fields if specifed the id statically,

It is populating fields if specifed the id statically,

And also able to get the object from ApexController,

enter image description here

  • May be its due to the missing rec.sobjectType='Deposit__c'; in the record retrieved from Apex class. Can you add this property in the newDep attribute after getting response from Apex? Feb 2 '17 at 13:51
  • @SantanuHalder Thanks for reply, I've added that one also before setting attribute, But still i'm not getting them, And if i set the Date and Amount fields in controller those are reflecting, but not for look up fields
    – SFDC_Igle
    Feb 2 '17 at 13:59
  • @SantanuHalder Thanks for solution, Its a good try though it is not getting populated even though i made that parsed and then setting attribute,
    – SFDC_Igle
    Feb 3 '17 at 10:03

This is not a direct answer to your question. But I thought my findings should be put here.

I have tried your code in my dev org and I was not able to change the inputField value on click of that button. Sigh!

I did some R&D and found this knowledge sharing.

Although he talks about sightly different issue but seems like force:inputField has lots of known issues which are yet to be fixed.

I have tried to use outputField in place of inputField and surprisingly it worked every time. So I believe its an issue with force:inputField.

As suggested in the above, I tried to put the force:inputField as the immediate child of the component, it was a partial success. I was able to get record suggestions as dropdown but once selected, I was not able to change it programmatically.

I have worked with Opportunity record and the force:inputField was bound to AccountId of Opportunity. The default attribute looks like this when loaded and stringified -

aura:attribute -

<aura:attribute name="newDep" type="Opportunity" default="{ 'sobjectType': 'Opportunity', 'AccountId': '0019000001ovYA6AAM'}"/> 


{"sobjectType":"Opportunity","AccountId":"0019000001ovYA6AAM","Account":{"sobjectType":"Account","Name":"A Pictures"}}

Notice the Account name population although I haven't set it. I just set the AccountId. So when I was changing the record using button click I tried to form a similar JSON string and parsed it as Opportunity and saved in the aura:attribute to see the changes. Like this -

    var newopp = JSON.parse('{"sobjectType":"Opportunity","AccountId":"0019000001XHa1O","Account":{"sobjectType":"Account","Name":"Hallie"}}');
   component.set("v.newDep", newopp);

But alas! another dead end.

I would suggest you to play with it some more. I hope my findings will help you somehow. If you still face the issue, try to reach Salesforce Support.

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.