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
rajesh k 10rajesh k 10 

how to populate Account Related contacts in contact lookup in an visualforce page?

Himanshu ParasharHimanshu Parashar
Hi Rajesh,

In your controller you can easilly assign contact id in contact lookup. what issue you are facing ?
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Rajesh,
You can put a look up filter into the Contact Look up field of your object for which you are implementing the Visualforce page like that,
User-added image

Please keep in mind you need a look up field with relation to Account Object proior to develop this filter into your Contact look up field.

Now your visualforce page will be like this ,
 
<apex:page standardController="Custom_Object__c">
    <apex:form >
        <apex:inputField value="{!Custom_Object__c.Account__c}"/>
        <apex:inputField value="{!Custom_Object__c.Contact__c}"/>
    </apex:form>
</apex:page>

And it is done. :)
 Thanks. 
rajesh k 10rajesh k 10
Hi,
   I am trying to like below
Page:

<apex:page standardController="Apple__c" extensions="Autopopulation">

<apex:form >
   <apex:inputtext id="Project1" value="{!accText }" onblur="functionvalidateProject();" >
                                    <c:autocompletecomp1 objectname="Apple__c"  searchField="Name" autocomplete_textbox="{!$Component.Project1}" />
                                    <apex:inputhidden value="{!acc.account_c}" id="Project1_lkid">
                                    <apex:actionSupport event="onchange" action="{!passProjectId}">
                                    <apex:param name="proId" value="{!apple.name}"/>
                                    </apex:actionSupport> 
                                    </apex:inputhidden> 
                           
      </apex:inputtext>
<apex:inputfield value="{!apple.Contact__c}"/>
      
</apex:form>   </apex:page>

Controller:
public class Autopopulation {

 public apple__c apple{ get; set; }
    public String accText { get; set; }
        public Autopopulation(ApexPages.StandardController controller) {
        this.apple= (apple) controller.getRecord();
        
         if(apple.id != NULL)
         {
         
         apple=[SELECT id,Account__c,Contact__c FROM apple__c WHERE id = :apple.Id ];
         accText =apple.Id;           
    
         }

 }
     public PageReference passProjectId()
        {
            String projectId = ApexPages.currentPage().getParameters().get('proId');
            System.debug(projectId);
            return null;
        }
}

Account and contacts are lookup in apple__c object.When i populate account through autocomplete how to populate account related contacts in contact lookup?
Prosenjit Sarkar 7Prosenjit Sarkar 7

How can you auto populate contacts ? If an account has more than one Contact then which will be autopupolated ? However, your extension class has some compiler errors. It can't be save into system.