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
siva krishna 61siva krishna 61 

how to write vf page two objects displayed side by side in salesforce

                        create vf page which display Account name (left side ) && List of contacts of that Account in Right side
Amit Singh 1Amit Singh 1
Hello Shiv,

Use below code for VF page.
<apex:page standardController="Account">
<apex:pageBlock title="Related Contacts">
      <apex:pageBlockSection columns="2">
          
          <apex:pageBlockTable value="{!Account}" var="acc">
              <apex:column headerValue="Account Name">
                  <apex:outputField value="{!acc.Name}"/>
              </apex:column>
              <apex:column headerValue="Contacts">
                  <apex:repeat value="{!acc.Contacts}" var="con">
                      <apex:outputField value="{!con.Name}"/><br/>
                  </apex:repeat>
              </apex:column>
          </apex:pageBlockTable>
      </apex:pageBlockSection>
  </apex:pageBlock>
</apex:page>
Let me know if this helps :)

Thanks!
Amit Singh
 
Ankur Saini 9Ankur Saini 9
Hi siva krishna

try this:--
<apex:page controller="AccountContactController" docType="HTML-5.0" sidebar="false" readOnly="true">

<style>
#manTable1 td{
border:1px solid Gray;
padding:5px;
}
</style>

<div style="width:100%" >
<apex:form >
   <table id="manTable1" style="border:1px solid black;border-collapse:collapse">
        <tr style="font-weight:600; background-color:#1797c0; font-size: 1.1em">
             <td style="color:#fff;padding-left: 3px;">Account Name</td> <td style="color:#fff;padding-left: 3px;">Contact Name </td>
        </tr>
        <apex:repeat value="{!MapOfAccountWithContact}" var="accountName">                    
            <tr style="background-color: #fbfbfb;">
                <td>{!accountName}</td><td></td>               
            </tr>           
                <apex:repeat value="{!MapOfAccountWithContact[accountName]}" var="conObj">
                    <tr style="background-color: #fbfbfb;">
                        <td></td><td>{!conObj.name}</td>                        
                    </tr>                                                                  
                </apex:repeat>                   
        </apex:repeat>
    </table> 
</apex:form>
</div>    
</apex:page>





public class AccountContactController{

    public map<string,list<Contact>> MapOfAccountWithContact{get;set;}
    
    public AccountContactController(){
        MapOfAccountWithContact = new map<string,list<Contact>>();
        for(account acc : [select id,name,(select id,name from contacts) from account]){
            if(acc.contacts.size()>0)
            MapOfAccountWithContact.put(acc.name,acc.contacts);           
        }       
    }
}


Thanks
Ankur Saini