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
SFDC 18SFDC 18 

Compile error in VF custom object page to render a PDF

This is my VF page code for Rendering a PDF for custom Object as below
<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">
<head>
    <style>
    body { font-family: 'Arial Unicode MS'; }

@page{
        size: letter;
        margin:10%;
        @top-left{
        	content: "Dear,";
        	font-family: Helvetica, Arial, sans-serif;
			font-size: 12px;
		}
        @bottom-right{
        	content: "Yours Sincerely,";
        	font-family: Helvetica, Arial, sans-serif;
			font-size: 10px;
		}
   }
body {
        font-family: Helvetica, Arial, sans-serif;
		font-size: 11px;
}
    </style>
</head>
	<div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
    <h1> Letter</h1>
    </center>
    <p>{!custom_object__C.Name__C</p>    
</apex:page>

Controller page
public class MyController {
    
    private final custom_object__c customobject;
        
        public MyController(){
            customobject = [SELECT Id, Name__c FROM custom_object__c 
                        LIMIT 1];
        }
        public custom_object__c getcustom_object__c(){
            return customobject;
        }
        public PageReference save() {
            update customobject;
            return null;
        }
    }

I got the error Unknown property 'MyController.custom_object__C' in my VF page​​

Due to this compile error, in the preview screen I got the display of only top left, bottom right, centre but no data related to "<p>{!custom_object__C.Name__C</p>" line
Best Answer chosen by SFDC 18
Sai harsha 7Sai harsha 7
Hello SFDC18

Please put the getter and setter methods to the variable in the controller .

Example :  private final custom_object__c customobject {set;get;}




Thanks & Regards
Srikanth
Salesforce Developer

All Answers

SFDC 18SFDC 18
Even after changing <p>{!custom_object__C.Name__C</p>    to <p>{!customobject.Name__C</p>   I got the same Unknown Property Error 'MyController.customobject'
Sai harsha 7Sai harsha 7
Hello SFDC18

Please put the getter and setter methods to the variable in the controller .

Example :  private final custom_object__c customobject {set;get;}




Thanks & Regards
Srikanth
Salesforce Developer
This was selected as the best answer
Raj VakatiRaj Vakati
Here is the complete code 
 
<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">
<head>
    <style>
    body { font-family: 'Arial Unicode MS'; }

@page{
        size: letter;
        margin:10%;
        @top-left{
        	content: "Dear,";
        	font-family: Helvetica, Arial, sans-serif;
			font-size: 12px;
		}
        @bottom-right{
        	content: "Yours Sincerely,";
        	font-family: Helvetica, Arial, sans-serif;
			font-size: 10px;
		}
   }
body {
        font-family: Helvetica, Arial, sans-serif;
		font-size: 11px;
}
    </style>
</head>
	<div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
    <h1> Letter</h1>
    </center>
    <p>{!customobject.Name__C</p>    
</apex:page>


public class MyController {
    
    public   custom_object__c customobject{get;set;}
        
        public MyController(){
            customobject = [SELECT Id, Name__c FROM custom_object__c 
                        LIMIT 1];
        }
           
    }

 
SFDC 18SFDC 18
Thank You. I'm able to run the PDF now.

How to add generate PDF button to my object if the VF page contains custom controller?
Sai harsha 7Sai harsha 7
Hello SFDC18

firstly you can create a custom button then select display type should be Detail Page Button then behaviour Execute javascript ..

content source : on click java script

In the Dialog Box :
  
window.location = 'apex/yourVfpageName';

Try this one it will help you to acheive this requirement.




Thanks & Regards
Srikanth
Salesforce Developer


 
SFDC 18SFDC 18
Thank you, Srikanth. I have created the button, but it should appear on my page only when my status is approved. for that, I have written the on clickJS as {!IF({!ISPICKVAL(Letter__c.Status__C, approved)},window.location = 'apex/Letter', null)} I got this error : Error: Syntax error