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
Quddus Ololade 4Quddus Ololade 4 

Unable to get the value in force:outputfield on pageload

​My component code:
​My component code:

​My component code:

<aura:component controller="AccountController" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global"  >
    <ltng:require styles="/resource/slds221/assets/styles/salesforce-lightning-design-system.min.css" />
    <aura:attribute name="edit" type="Boolean" default="true"/>
    <aura:attribute name="save" type="Boolean" default="false"/>
    <aura:attribute name="cancel" type="Boolean" default="false"/>
    <aura:attribute name="Account" type="Account" default="{ 'sobjectType': 'Account' }"/>
    <aura:attribute name="recordId" type="String" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <center>
        <aura:if isTrue="{!v.edit}">
            <lightning:button variant="neutral" label="Edit Info" class="slds-align_absolute-center" onclick="{!c.handleEdit}"/>
        </aura:if>
        <aura:if isTrue="{!v.save}">
            <lightning:button variant="neutral" label="Save Info" class="slds-align_absolute-center" onclick="{!c.handleSave}"/>
        </aura:if>
        <aura:if isTrue="{!v.cancel}">
            <lightning:button variant="neutral" label="Cancel" class="slds-align_absolute-center" onclick="{!c.handleCancel}"/>
        </aura:if>
    </center>
    <div class="slds-form slds-form_stacked">
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <lightning:select name="selectItem" label="Process Item" disabled="{!!v.save}">
                    <option value="1">Yes</option>
                    <option value="2">No</option>
                </lightning:select>
            </div>
            <label class="slds-form-element__label" for="input-id-03">Process Contact ?</label>
            Save: {!v.Account.Contact__c}
            <aura:renderIf isTrue="{!v.save}">
                <div class="slds-form-element__control">
                    <force:inputField value="{!v.Account.Contact__c}" class="foo" >{!v.Account.Contact__c}</force:inputField>
                </div>
            </aura:renderIf>
            <aura:renderIf isTrue="{!!v.save}">
                <div class="slds-form-element__control">
                  <force:outputField aura:id="accountLookupOutput" value="{!v.Account.Contact__c}"/>
                </div>
            </aura:renderIf>
        </div>
    </div>
</aura:component>
My Js:
({
    doInit : function(component, event, helper) {
        var getaccountdata = component.get("c.getAccount");
        getaccountdata.setParams({ "Id": component.get("v.recordId")});
        getaccountdata.setCallback(this, function(response){      
            var state = response.getState();
            if (state === 'SUCCESS'){
                console.log(response.getReturnValue());
                component.set("v.Account",response.getReturnValue());
            }
        });
        $A.enqueueAction(getaccountdata);
    }

I  get the associated account data for that account and then I set it back to the account variable attribute.
But on page load, I dont see the value in force:outputfield even though that account has that value populated in the field. Its the standard field so ideally it should have shown the value which is already in the account with the standard view .

Can anyone help me on this? if I missed something here
I also tried to put force:output field at the top as well but still the same its blank on page load
 
Best Answer chosen by Quddus Ololade 4
Quddus Ololade 4Quddus Ololade 4
Ok I finally got the issue, in the apex controller for the lookup fields, I need to use the related fields as well

All Answers

Quddus Ololade 4Quddus Ololade 4
While selecting any value in the force:inputfield, the outputfield gets populated but not while the page loadsUser-added image
ShubhopediaShubhopedia
Hi Quddus,

1. Check with the Apex method that you are calling to see if that field is been queried in SOQL.
2. Checking with help of console.debug in the response that the required value is received in the doInit method.
3. In component try removing the default value that you have defined and check if the return type of your SOQL in apex similar to the attribute you are typing in the component.

Let me know if this helps.
Thanks
Quddus Ololade 4Quddus Ololade 4
Hi @shubhopedia,

1) Yes, I checked that since I am getting the value in the component as well line 34  Save: {!v.Account.Contact__c}, i get the id here fom apex
2) Yes in the js controller line no. 8 console.log(response.getReturnValue()); i get the value as well
3)  Yes I just tried that I removed that default , but no luck
Quddus Ololade 4Quddus Ololade 4
Ok I finally got the issue, in the apex controller for the lookup fields, I need to use the related fields as well
This was selected as the best answer