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
raghav kumar 7raghav kumar 7 

Create a lookup relationship for account and contact with vf page. when you click on account related contact will displayCreate a lookup relationship for account and contact with vf page. when you click on account related contact will display

Create a lookup relationship for account and contact with vf page. when you click on account related contact will displayCreate a lookup relationship for account and contact with vf page. when you click on account related contact will display
Suraj TripathiSuraj Tripathi
Hi raghav kumar,

please find the code below for your requirement:

VF Page
<apex:page controller="SampleTest" sidebar="false">
    <apex:form >
        <apex:pageBlock title="Account Table">
            <apex:pageBlockTable value="{!Acclst}" var="A">
            <apex:column headerValue="Account Name" > 
            <apex:commandLink value="{!A.Name}" action="{!showContacts}" rerender="Accwithcon">
              <apex:param value="{!A.Id}" name="idForConts" assignTo="{!recid}"/>
            </apex:commandLink>
            </apex:column>  
            <apex:column value="{!A.Id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock> 
    
    <apex:pageBlock title="Contacts" id="Accwithcon" >
      <apex:pageBlockTable value="{!contacts}" var="contact" >
          <apex:column value="{!contact.id}"/>
          <apex:column value="{!contact.Lastname}"/>
          <apex:column value="{!contact.firstname}"/>
      </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Controller Class
public class SampleTest {
    
	 public string recid{get;set;}
     public string reccon{get;set;}
    public boolean flag{get;set;}

   public string row{ get; set;}
   public list<Account> Acclst{get;set;}

   public List<Contact> contacts {get; set;}

   public Nov25Task(){

   Acclst = [select Id,Name from Account limit 10];
   contacts=null;
       flag=false;
   }

  public void showContacts()
  {
     contacts=[select id, FirstName, LastName from Contact where AccountId=:recId];
      }
}

​Regards,
Suraj

 
raghav kumar 7raghav kumar 7
thanks bro
raghav kumar 7raghav kumar 7
bhai ek master detail ka que ta. Que same hi but master detail par hai