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
thunksalotthunksalot 

Apex component unknown property error

I'm using the online Visualforce documentation to try to learn how to render a visualforce component as a PDF attachment on a visualforce email.  But, when I try creating a component exactly like the one in the documentation I get an error.  Am I missing something or is there a mistake in the documentation??

 

Here's the code I can't get to work (gray box below).  When I copy and paste it into a new visualforce component, it won't save and gives me this error message: Error: Unknown property 'account'

 

Defining a Custom Component as an Attachment

By creating a custom component and using it on the Visualforce email form and to render the PDF for the email, users can see a preview of the content they are trying to send.

The following markup defines a custom component namedattachmentthat represents the attachment for the email:
<apex:component access="global">
  <h1>Account Details</h1>
  
  <apex:panelGrid columns="2">

      <apex:outputLabel for="Name" value="Name"/>
      <apex:outputText id="Name" value="{!account.Name}"/>
      
      <apex:outputLabel for="Owner" value="Account Owner"/>
      <apex:outputText id="Owner" value="{!account.Owner.Name}"/>
      
      <apex:outputLabel for="AnnualRevenue" value="Annual Revenue"/>
      <apex:outputText id="AnnualRevenue" value="{0,number,currency}">
          <apex:param value="{!account.AnnualRevenue}"/>
      </apex:outputText>
      
      <apex:outputLabel for="NumberOfEmployees" value="Employees"/>
      <apex:outputText id="NumberOfEmployees" value="{!account.NumberOfEmployees}"/>
      
  </apex:panelGrid>
</apex:component>
Replace yourattachmentPDFpage like this:
Best Answer chosen by Admin (Salesforce Developers) 
thunksalotthunksalot

After coming back to this and getting hung up on it again 2 months later, I thought I should record here what the correction is that needs to be made in order for the code in the Create An Email Attachment documentation to work correctly.  I'll report this to SF as well.

 

The "attachment" component needs to have an attribute tag added to it to receive an Account Object that you will pass to it from the "attachmentPDF" visualforce page defined earlier in the documentation. 

<apex:component access="global">

<!-- ADD THIS ATTRIBUTE TAG TO PASS IN THE ACCOUNT OBJECT -->
<apex:attribute name="account" description="" type="Account" />

  <h1>Account Details</h1>
  
  <apex:panelGrid columns="2">

      <apex:outputLabel for="Name" value="Name"/>
      <apex:outputText id="Name" value="{!account.Name}"/>
      
      <apex:outputLabel for="Owner" value="Account Owner"/>
      <apex:outputText id="Owner" value="{!account.Owner.Name}"/>
      
      <apex:outputLabel for="AnnualRevenue" value="Annual Revenue"/>
      <apex:outputText id="AnnualRevenue" value="{0,number,currency}">
          <apex:param value="{!account.AnnualRevenue}"/>
      </apex:outputText>
      
      <apex:outputLabel for="NumberOfEmployees" value="Employees"/>
      <apex:outputText id="NumberOfEmployees" value="{!account.NumberOfEmployees}"/>
      
  </apex:panelGrid>
</apex:component>

 

Then, the attachmentPDF visualforce page has to be modified to pass the Account object.

<apex:page standardController="Account" renderAs="PDF">
  
  <c:attachment account="{!account}" />
  
</apex:page>

 

 

All Answers

AmitSahuAmitSahu
I think the relatedto tag is missing if you r trying to use this vf in email.
aballardaballard

There is a mistake in the documentation.   If the component wishes to reference an Account object, it has to be passed to it as an attribute (or obtained via a controller)

thunksalotthunksalot

Thanks so much aballard!  I was starting to feel very inept!  Glad to know it wasn't me.

thunksalotthunksalot

After coming back to this and getting hung up on it again 2 months later, I thought I should record here what the correction is that needs to be made in order for the code in the Create An Email Attachment documentation to work correctly.  I'll report this to SF as well.

 

The "attachment" component needs to have an attribute tag added to it to receive an Account Object that you will pass to it from the "attachmentPDF" visualforce page defined earlier in the documentation. 

<apex:component access="global">

<!-- ADD THIS ATTRIBUTE TAG TO PASS IN THE ACCOUNT OBJECT -->
<apex:attribute name="account" description="" type="Account" />

  <h1>Account Details</h1>
  
  <apex:panelGrid columns="2">

      <apex:outputLabel for="Name" value="Name"/>
      <apex:outputText id="Name" value="{!account.Name}"/>
      
      <apex:outputLabel for="Owner" value="Account Owner"/>
      <apex:outputText id="Owner" value="{!account.Owner.Name}"/>
      
      <apex:outputLabel for="AnnualRevenue" value="Annual Revenue"/>
      <apex:outputText id="AnnualRevenue" value="{0,number,currency}">
          <apex:param value="{!account.AnnualRevenue}"/>
      </apex:outputText>
      
      <apex:outputLabel for="NumberOfEmployees" value="Employees"/>
      <apex:outputText id="NumberOfEmployees" value="{!account.NumberOfEmployees}"/>
      
  </apex:panelGrid>
</apex:component>

 

Then, the attachmentPDF visualforce page has to be modified to pass the Account object.

<apex:page standardController="Account" renderAs="PDF">
  
  <c:attachment account="{!account}" />
  
</apex:page>

 

 

This was selected as the best answer
raj123raj123

Thanks, thunksalot for coming back on your post and correcting, for starter this helps a lot.

Guillaume MorinGuillaume Morin
Thank you very much for this