0

Below is my 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);
    }

Apex Code:

  @AuraEnabled
    public static Account getAccount(String Id) {
        system.debug('AccId:-'+Id);
        return [select Id,Contact__c from Account WHERE ID =:Id Limit 1];
    }

I get the associated data for that account and then i set it back to the account attribute.

But on page load I dont see the value in force:outputfield even though that account has that value populated in field.

Can anyone help me on this? if I missed something here I tried to put force:output field at the top as well but still the same its blank

While selecting any value in the force:inputfield, the outputfield gets populated but not while the page loads

enter image description here

4
  • Are you getting any error(s)? – itzmukeshy7 Mar 25 '18 at 15:18
  • No nothing in the console i checked. From the input field when i select any value i see that gets populated in output field but on the page load, nothing appears it is just blank – Quddus Mar 25 '18 at 15:20
  • 1
    Share the Apex code as well; – itzmukeshy7 Mar 25 '18 at 15:39
  • just pasted in the question – Quddus Mar 25 '18 at 15:49
0

I finally got the issue, in the apex controller for the lookup fields, I need to use the related fields as well

@AuraEnabled
    public static Account getAccount(String Id) {
        system.debug('AccId:-'+Id);
        return [select Id,Contact__r.Name from Account WHERE ID =:Id Limit 1];
    }

Thanks @itzmukeshy7

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.