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
Hemalatha  ParuchuriHemalatha Paruchuri 

How to populate account name based on contact select through vf page

We have a custom object attendee/speaker. and it has lookup on to contact . i want populate  account name automatically how to do this

<apex:page standardController="Attendee_Speaker_Conferences__c" extensions="Attendeespeakcc">

<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >

<apex:commandButton action="{!Save}" value="Save"/>


<apex:commandbutton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>

<apex:pageBlock title="Attendee/Speaker Conferences Edit">
<apex:pageblockSection columns="2">
<apex:inputField value="{!Attendee_Speaker_Conferences__c.Contact__c}"/>
<apex:inputField value="{!Attendee_Speaker_Conferences__c.CurrencyIsoCode}"/>

<apex:inputField value="{!Attendee_Speaker_Conferences__c.Opportunity__c}"/>
<apex:outputField value="{!Attendee_Speaker_Conferences__c.Email__c}"/>
<apex:inputField value="{!Attendee_Speaker_Conferences__c.Feedback__c}"/>
<apex:outputField value="{!Attendee_Speaker_Conferences__c.contact__r.account.Id}"/>

<apex:inputField value="{!Attendee_Speaker_Conferences__c.Role__c}"/>






</apex:pageblockSection>

</apex:pageBlock>



</apex:pageBlock>



</apex:form>
 
</apex:page>



public with sharing class Attendeespeakcc {
 private ApexPages.StandardController sc;
    public Attendeespeakcc(ApexPages.StandardController sc) {
     this.sc = sc;
        
    }
    
      public PageReference save() {
    
        PageReference detailPage = sc.save();
        if (detailPage != null) {
            // Construct URL of edit page or whatever other page you want
            PageReference editPage = new PageReference('/apex/Attendeespeakerconferenceoverride');
            return detailPage;
        } else {
            return detailPage;
        }
    }
    public PageReference cancel() {
    
        PageReference detailPage = sc.cancel();
        if (detailPage != null) {
            // Construct URL of edit page or whatever other page you want
            PageReference editPage = new PageReference('https://cs21.salesforce.com/a09/o');
            return detailPage;
        } else {
            return detailPage;
        }
    }
    }


 
Vishal Negandhi 16Vishal Negandhi 16
If you mean this is to be added on page load itself.. 
Just add this line on your page:

<apex:inputField value="{!Attendee_Speaker_Conferences__c.Contact__r.AccountId}"/>