+ Start a Discussion
jbozajboza 

Rendered PDF keeps giving the same record.

I have created a pdf to show the comments in the task object for the record I am viewing. This links to a button that opens the pdf in current window. I would like to open in a new window. Also once I rendered this pdf it now will give the same values even if I chooses a different record. I quess this means the value did not reset. Here is the code.

 

Controller:

 

public class TaskController{

public Task tsk{get;set;}
    public TaskController(){
        tsk=[select Description from Task limit 1];
        tsk.Description=tsk.Description.replace('\n','<br/>');      
    }  
}

 

VF Page:

 

<apex:page controller="TaskController" showHeader="false" renderAs="PDF">
   
    <div align="center" width="550px">
        <h1>Current Email</h1>
    </div>   
    <div align="left" width="550px">
         <apex:outputtext escape="false" value="{!tsk.Description}"></apex:outputtext>       
           </div>         
</apex:page>

Best Answer chosen by Admin (Salesforce Developers) 
Vinita_SFDCVinita_SFDC

Hi,

 

Try like this:

 

tsk=[select Id, Description from Task WHERE Id = :ApexPages.currentPage().getParameters().get('id) limit 1];

All Answers

Vinita_SFDCVinita_SFDC

Hi,

 

Try like this:

 

tsk=[select Id, Description from Task WHERE Id = :ApexPages.currentPage().getParameters().get('id) limit 1];

This was selected as the best answer
jbozajboza

This keeps giving me an error for no page break allowed

jbozajboza

So I got an error when running that said List has no rows for assignment to SObject.