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
ShravanKumarBagamShravanKumarBagam 

Using Standardcontroller Account ,how can i get the contact records?

Hi

Best Answer chosen by Admin (Salesforce Developers) 
rohitsfdcrohitsfdc

You need to use standardlistcontroller for that

 

<apex:page standardController="account" recordSetVar="accounts" tabstyle="account" sidebar="false">
<apex:pageBlock >
<apex:form ><apex:dataList value="{!accounts}" var="a">
    <apex:pageblocksection title="Contacts for account {!a.name}" >
        <apex:repeat value="{!a.contacts}" var="c">
           <apex:inputField label="Contact name" value="{!c.name}"/><br/>
        </apex:repeat></apex:pageblocksection>

    </apex:dataList>    </apex:form>


</apex:pageBlock>
</apex:page>

 Change the UI according to your requirement

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

<apex:page standardController="Account" >

<apex:pageBlock >

 

<apex:pageBlockTable value="{!account.contacts}" var="contact">

<apex:column value="{!contact.name}"/>

<apex:column value="{!contact.email}"/>

</apex:pageBlockTable>

 

</apex:pageBlock>

 

</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

rohitsfdcrohitsfdc

HI,

you can fetch contacts associated with a account using their relationship (master-child).

 

<apex:page standardController="account" >

    <apex:form >
        <apex:pageBlock title="Contact details for account" >
            <apex:pageBlockTable value="{!account.contacts}" var="con">
            <apex:column value="{!con.name}"/>
            <apex:column breakBefore="{!con.id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 Make sure you enter account id in the browser.

for ex

 https://c.ap1.visual.force.com/apex/contactdetails?id=00190000003OHIS

 

where 00190000003OHIS is the id of account.

 

 

ShravanKumarBagamShravanKumarBagam

But i've to get the Multiple record's of account and its contacts

ShravanKumarBagamShravanKumarBagam

But i've to get the Multiple record's of account and its contacts

rohitsfdcrohitsfdc

You need to use standardlistcontroller for that

 

<apex:page standardController="account" recordSetVar="accounts" tabstyle="account" sidebar="false">
<apex:pageBlock >
<apex:form ><apex:dataList value="{!accounts}" var="a">
    <apex:pageblocksection title="Contacts for account {!a.name}" >
        <apex:repeat value="{!a.contacts}" var="c">
           <apex:inputField label="Contact name" value="{!c.name}"/><br/>
        </apex:repeat></apex:pageblocksection>

    </apex:dataList>    </apex:form>


</apex:pageBlock>
</apex:page>

 Change the UI according to your requirement

 

This was selected as the best answer