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
Niamh LNiamh L 

Display Related Custom Field on VF Page

Hi, 

I am creating a Visualforce page and want to display the pet breed available from the pet custom object. I have a field on the case object called Pet Name (Pet__c) which is a lookup field to the pet object to select the pet.
But on the VF page I want to display the breed and age of the pet too, but i get the error Unknown property 'String.Pet_Breed__c'
See code for page below:

  <tr>
                <td valign="top" style="padding:3px;"></td>
                <td height="30" width="300" valign="top" style="padding:3px;">Breed of Pet:</td>
                <td width="300" valign="top" style="padding:3px;">{!Case.Pet__c.Pet_Breed__c}</td>
  </tr>

Any help appreciated.
 
Best Answer chosen by Niamh L
Maharajan CMaharajan C
Try the below one:

In order to access related object’s data you need to append __r instead of __c. In case of standard object you don’t need to append __r. They are accessible using simple name. In your case you can access your data as given below :

{!Case.Pet__r.Pet_Breed__c}

Can you please Let me know if it works or not and also If you face any problems!!!

If it works don't forget to mark this as a best answer!!!

Thanks,
​Raj

All Answers

Maharajan CMaharajan C
Try the below one:

In order to access related object’s data you need to append __r instead of __c. In case of standard object you don’t need to append __r. They are accessible using simple name. In your case you can access your data as given below :

{!Case.Pet__r.Pet_Breed__c}

Can you please Let me know if it works or not and also If you face any problems!!!

If it works don't forget to mark this as a best answer!!!

Thanks,
​Raj
This was selected as the best answer
Niamh LNiamh L
Thanks Maharaja, this worked!

Niamh