+ Start a Discussion
Baird_SBaird_S 

Variable pagereference?

From the opportunity object, I'm allowing users to select from a list of thank-you letter templates which are stored as VF pages.  When they click on one of the list, I'd like to render that particular page, so they can print it and save it.

 

I'm able to render the list of VF pages, but can't get the PageReference to redirect to the chosen VF page.  I'm fairly new at this, and maybe there's a much easier way to do it.

 

When users select the thank-you letter format (in a VF Page), then the relevant page coding is:

 

<apex:commandLink action="{!renderLetter}" value="{!tt.Name}">                       

<apex:param name="TemplateName" value="{!tt.Name}"/>                   

</apex:commandLink>

 

This calls the renderLetter method:

 

public PageReference renderLetter() {   

string ChosenTemplate = System.currentPageReference().getParameters().get('TemplateName');   

PageReference renderLetter = Page.ChosenTemplate;

return renderLetter;   

}

 

But of course I simply get the error message that no Page called ChosenTemplae exists.  I haven't been able to find out how to get the Page.ChosenTemplate to recognize that ChosenTemplate is a variable, nor figure out the right way around this.

 

Any answers?  Many thanks in advance for your help.

 

Baird

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

PageReference renderLetter = new PageReference(chosenTemplate);

 

All Answers

aballardaballard

PageReference renderLetter = new PageReference(chosenTemplate);

 

This was selected as the best answer
Baird_SBaird_S

Many thanks.  The overworked staff at the river and watershed organizations I work with will be really appreciative.  Now, on to my next error, er, learning opportunity.