Relationships Object Records in Visualforce Page

We can have a requirement to show master object record and the respective child records in a Visualforce Page. So, for that we don’t have to write code to retrieve child object record. We can show the child records without query it.

Here is an example I’m rendering a Visualforce Page as “pdf” with Account information and the respective contact records information.

Visualforce Page:

<apex:page standardController="Account" showHeader="false" renderAs="pdf">
    
    <b>Name:</b> {!Account.Name}<br/>
    <b>Account Number:</b> {!Account.AccountNumber}<br/>
    <b>Type:</b> {!Account.Type}<br/>
    <b>Industry:</b> {!Account.Industry}<br/>
    <b>Phone:</b> {!Account.Phone}<br/>
    <p/>
    
    <table width="100%" cellpadding="2" cellspacing="2">
        <tr>
            <td><b>First Name</b></td>
            <td><b>Last Name</b></td>
            <td><b>Email</b></td>
            <td><b>Phone</b></td>
        </tr>
        <apex:repeat value="{!Account.Contacts}" var="con">
            <tr>
                <td>{!con.FirstName}</td>
                <td>{!con.LastName}</td>
                <td>{!con.Email}</td>
                <td>{!con.Phone}</td>
            </tr>
        </apex:repeat>
    </table>
</apex:page>