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
_why the unlucky stiff_why the unlucky stiff 

Formatting PDF

Hello I have a page that I am trying to generate as a PDF. I am trying to access values from a custom object 'FieldVisitors__c' to display on the PDF page. So far, I have had no luck. Could some gentleman explain how to access fields from this custom object to display on the PDF page?

 

As you can see below, I was only able to get the User name and date to work. I need to access fields like FieldVisitors__c.Subject

Account Name (A lookup field to Account object) etc...

 

Can someone point me to the right direction? I am much obliged.

 

<apex:page standardController="FieldVisitors__c" renderAs="PDF" >
    <h1>Field Visit Report</h1>
    <h2>Report Created By {!$User.FirstName} on {!NOW()}</h2>
</apex:page>

 

Rahul SharmaRahul Sharma

Since its a standard controller so provide id of FieldVisitors__c to the url.

And for the field name, check the way you access the fieldname in soql query.

If The field name in FieldVisitors__c is Subject_Account__c.Name,

then use FieldVisitors__r.Subject_Account__c.Name

 

Check below code to access Name field.

<apex:page standardController="FieldVisitors__c" renderAs="PDF" >
    <h1>Field Visit Report</h1>
    <h2>Report Created By {!$User.FirstName} on {!NOW()}</h2>
    {!FieldVisitors__c.Name}
</apex:page>