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
Connor ScottConnor Scott 

custom related list on visualforce pdf page.

Hello all,
Im currently trying to build a pdf page for accounts, and that page has a section that pulls a list of all open opportunities for that account. Below are relevant samples of my code.
<apex:page standardController="Account" extensions="ActProp" renderAs="pdf">
<apex:pageBlock title="Proposals">
        <apex:pageBlockTable value="{!Account.Opportunities}" var="o">
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.StageName}"/>
            <apex:column value="{!o.Amount}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
public class ActProp{
   public ActProp(ApexPages.StandardController cont) {}
   List<Opportunity> props = [Select Name, StageName, Amount, AccountId from Opportunity where StageName = 'Proposal Creation' or StageName = 'Proposal Revision' or StageName = 'Proposal Review' or StageName = 'Negotiation'];
      public List<Opportunity> getprops(){
      return props;
      } 
}
Ive only been able to work with apex for less than a week, so my code may be just natually clunky. Whenever I send the visualforce page and apex class into production, They just barely dont meet the 75% test rate, and most of the errors mention a missing required field Company__c.  My question at this point is where would this field go? ive tried putting it in the query, in the vf page, and I just can't figure out where to slot it in. Any insight is greatly appreciated, as i'm guessing my code has more than a single problem.
Regards, 
Connor 
 
Deepali KulshresthaDeepali Kulshrestha
Hi Connor,

- I read your problem and implemented it in my Org and it is working fine.
- Please use the below code and customize as per your need: -
-------------- Apex Controller------- -----
public class ActProp{
    public ActProp(ApexPages.StandardController cont) {}
    List<Opportunity> props = [Select Name, StageName, Amount, AccountId from Opportunity where StageName = 'Proposal Creation' or StageName = 'Proposal Revision' or StageName = 'Proposal Review' or StageName = 'Negotiation'];
    public List<Opportunity> getprops(){
        return props;
    }
}
----------------VF Page-------------------

<apex:page standardController="Account" extensions="ActProp"  renderAs="PDF">
    <apex:pageBlock title="Proposals">

        <div >


                <table width="100%">
                   <thead>
                   <tr>
                       <th>Name</th>
                       <th>StageName</th>
                       <th>Amount</th>
                   </tr>
                   </thead>
                    <tbody>
                    <apex:repeat var="c" value="{!props}">
                        <tr>
                            <td>{!c.Name}</td>

                            <td>{!c.StageName}</td>

                            <td>{!c.Amount}</td>
                        </tr>

                    </apex:repeat>
                    </tbody>

                </table>

        </div>

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

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Connor ScottConnor Scott
I'm afraid that I still can't get my code into production, local tests provide 0% code coverage. I read somewhere that I need a test class for this, how would I go about creating this?