I am trying to create a Visualforce Page render as a PDF in which it will show the details for a record from where is executed(Object A) and certain data from an Object B that has Object A as a Lookup Field.

The Image above is a sample of the record where im pulling the info from. I know i need merge fields to pull up any field on this record. However, i want to pull data from the Carrier Submissions related list. now i dont want to pull info exactly as shown on the related list, i just want some of the columns.

Now, i do have some of the Visualforce page going already, im rendering an HTML as a PDF, i can work on this on my own.

I need help on being able to pull all the related records on Carrier Submission that have a stage of SUBMITTED.

From what i understand i need a class for this. By looking at some reference i tried creating one but i have no luck.

This is what i have so far(there might be a lot of errors there) :

 public class CarrierQuotesPDF {
    private List<CanaryAMS__Carrier_Quotes__c> quote;
    private CanaryAMS__Insurance_Product__c Quotes; 
    public CarrierQuotes(ApexPages.StandardController controller) {
        this.quote= (CarrierQuotes)controller.getRecord();
    public List<CanaryAMS__Carrier_Quotes__c> getqut()
        CanaryAMS__Carrier_Quotes__c con = [Select id, CanaryAMS__Insurance_Product__r.id FROM CanaryAMS__Carrier_Quotes__c where CanaryAMS__Stage__c = 'Submitted'];
        if (con.CanaryAMS__Insurance_Product__r == null)
         return null;
        qut = [Select CanaryAMS__Carrier__c.Name, CanaryAMS__Quote__c, CanaryAMS__Notes__c from CanaryAMS__Carrier_Quotes__c where CanaryAMS__Insurance_Product__r.id = :con.CanaryAMS__Insurance_Product__r.id];
        return quote;

As for my visualforce page, this is what i have so far: enter image description here

This is just a starter, and even tho i show a related list there i dont want to show a related list as it shows on my page layout.

Here is the code for the page in case i need change there :

<apex:page standardController="CanaryAMS__Insurance_Product__c" 
<table style="width: 100%;">
<td style="width: 265px;"><img style="float: left;" 
file=01561000000DXcV" alt="" width="227" height="54" /></td>
<td style="text-align: right; width: 467px;">
<p>Phone: {!$Organization.Phone}<br />Fax: {!$Organization.Fax}<br 
/>Website: www.InsuranceMedics.com</p>
<hr />
<div  style="text-align: right;"> Date: 
<apex:outputText value="{0,date, MM'/'dd'/'yyyy}">
<apex:param value="{!TODAY()}" /> 
<apex:relatedList list="CanaryAMS__Carrier_Quotes__r" />

  • 3
    Right now, your Visualforce page is not connected to your controller, and your controller won't compile at all. You may be able to accomplish this without a custom controller or extension, but you'll need to edit your question to be specific about your objective.
    – David Reed
    Commented Mar 5, 2018 at 3:11
  • @DavidReed well my objective was to be able to use the some of the fields of the related records that meet the criteria in the vf page. not sure where you want me to place this. I have more steps to accomplish after that but thats the step im stuck at. Commented Mar 7, 2018 at 2:10
  • You may check out www[dot]arrify[dot]com/generate-pdf-in-salesforce/ for step by step guide.
    – Kritik
    Commented May 8 at 7:23

1 Answer 1


You don't actually need the associated controller extension unless you need to perform some additional work or processing on the related records. You can access the related records and their fields just fine in a Visualforce page using only the standard controller by using the appropriate relationship name in your expressions:

<apex:page standardController="Account">
    <apex:repeat value="{! Account.Contacts }" var="c">
        <apex:outputText value="{! c.FirstName + ' ' + c.LastName }" /><br />

This page renders and shows all of the Account's Contacts. Note that you must use the relationship's name, which is defined on the lookup or master-detail field itself, and is not simply the name of the child object in most cases.

If you do need to perform additional processing, that would be the time to implement a controller extension with a property like

public List<ChildObject__c> childObjects {
    get {
         return [SELECT Id, Name 
                 FROM ChildObject__c 
                 WHERE ParentId__c = :recordId
                       AND Stage = 'Submitted'
                 ORDER BY Name];

You'd then declare a dependency in your Visualforce page on this controller extension with the extensions= attribute on <apex:page> and reference the {! childObjects } property to obtain the list.

Please note that the above are examples that you would need to adapt to your specific situation. You may find these links useful:

  • Hey @DavidReed, thanks so much for your help! I am workin on creating the controller, it would work better for me based on the criteria i am looking for. The console gave me an error on the ":recordId" function you had given me. it would tell me the "variable doesnt exist". I found that :ApexPages.currentPage().getParameters().get('id') might work however i still ran with some issues to finally save my controller. Commented Mar 14, 2018 at 20:46
  • Glad to be a help! Just replace recordId with the variable where you are storing the Account's Id.
    – David Reed
    Commented Mar 14, 2018 at 20:50
  • Thanks! David, i havent set a variable for the record's ids. I understand that the variable i need there is for the record where the visualforce page is being launch from. also, I am gettin some errors now on the console. please advise. see image: ibb.co/kGokAH Commented Mar 14, 2018 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .