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
NewBee21NewBee21 

My requirement is I want the contacts of the Account which I search with the look up (see screenshot) and then I will get contacts related to the account to me.

My requirement is I want the contacts of the Account which I search with the look up (see screenshot) and then I will get contacts related to the account to me.

heres what i achieved till the lookup part,but now stuck with how do i get contacts fetched to me of the account.

**controller**

public class freshcontroller1
{
public contact con {get;set;}
Account ac;

  public freshcontroller1(ApexPages.Standardcontroller controller)
 {
 con =new contact();
 }
public Account getAc()
{
return ac;
}
 
  public pagereference showcontact()
  {
  ac = [select id from Account where id=:con.accountid];
  System.debug('Ac  '+ac);
  return null;
  }  
  public pagereference Contact()
  {
  con=[select id,Name,Phone from Contact where id=:con.accountid];
  System.debug('contacts are '+con);
  return null;
  }
  
}


*VF Page**

<apex:page standardController="Account" extensions="freshcontroller1">
<apex:form > <apex:pageBlock title="Account information"/>
<apex:inputField value="{!con.accountid}"/>
<apex:commandButton action="{!showcontact}" value="Display contacts"/>
<apex:pageBlock > <apex:pageBlockTable value="{!con}" var="c"/>
</apex:pageBlock>
</apex:form>
</apex:page>
NewBee21NewBee21
Scrrenshot:

User-added image
CharuDuttCharuDutt
Hii NewBee
Try Below Code
<apex:page sidebar="false" controller="DisplayAccWithContact">
    <apex:form >      
        <apex:outputText value="Enter Account Name:"></apex:outputText>
        <apex:inputtext value="{!accName}" />
        <apex:commandButton value="ShowContacts" action="{!showContacts}" rerender="out" status="mystatus"/><br/>
        
        <apex:actionstatus id="mystatus" starttext="please wait contacts are loading.......">
            <apex:facet name="stop">
                <apex:outputpanel id="out">
                    <apex:pageBlock >
                        <apex:pageBlockSection >
                            <apex:pageBlockTable value="{!Contacts}" var="c" rendered="{!accName !=null}">
                                <apex:column headerValue="Name">
                                    {!c.Name}
                                </apex:column>
                                <apex:column headerValue="Phone">
                                    {!c.Phone}
                                </apex:column>
                                <apex:column headerValue="Email">
                                    {!c.Email}
                                </apex:column>
                            </apex:pageBlockTable>
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                </apex:outputpanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:form>
</apex:page>



public with sharing class DisplayAccWithContact {
    public String accName {get;set;}

    List<Account> lstacc = new List<Account>();
    List<contact> lstcon = new List<contact>();
    public List<contact> getContacts() {
       lstcon.clear();
       accIds.clear();
       lstacc.clear();      
       lstacc=[select id,name from Account where name=:accName];
       for(Integer i=0;i<lstacc.size();i++)
       {
           accIds.add(lstacc[i].Id);
       }
       
        lstcon =[select id,name,Phone, email,accountId from contact where accountid in : accIds];
        //system.debug('### List of Contacts for Test is ###'+ lstcon);
        return lstcon;
    }
    
    set<string> accIds = new set<string>();
    public pagereference showContacts() {
       return null;        
    }
}
Please Mark It As Best Answer If it Helps
Thank you!
 
NewBee21NewBee21
Hello Charu,Thanks a lot for the response.I appreciate it,but my requirment is I want to select an Account,using lookup logo  and when I select any Account, I want the contacts related to that Account to be shown. I will share with you the screenshot how how lookup is supposed to look like. User-added image