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
JamesZJamesZ 

Select a visualforce page based on the value of a picklist on custom object.

Please excuse my ignorance on something that may be quite simple for some of you. Thanks in advance for assisting me in learning how to maximize the potential of Salesforce.

 

I am using the free quote line item app from app exchange and would like to have the visualForce page that generates the PDF be dynamic. Possibly an if statement that will go up to the quote and check the value of the custom picklist I created, 'template__c' and then use this value to determine which visualforce page to use for the quote. The conditions might be something like this:

 

String template;
template = quote.template__c;  

 

if ( template == 'quote1' ) {
PageReference pdfPage = new PageReference( '/apex/quotePDF');
}

if ( template == 'quote2' ) {
PageReference pdfPage = new PageReference( '/apex/quotePDF');
}

 I could not figure out how to get the quote.template__c value and store it in a variable so that it could be used to select the correct template. This is the section of the controller that generates and attaches the PDF.

 

/* The action method that will generate a PDF document from the QuotePDF page and attach it to the quote provided by the standard controller. Called by the action binding for the attachQuote page, this will do the work and take the user back to the quote detail page. */

public PageReference attachQuote() {

/* Get the page definition */
PageReference pdfPage = new PageReference( '/apex/quotePDF' );

/* set the quote id on the page definition */
pdfPage.getParameters().put('id',quote.id);

/* generate the pdf blob */
Blob pdfBlob = pdfPage.getContent();

/* create the attachment against the quote */
Attachment a = new Attachment(parentId = quote.id, name=quote.name + '.pdf', body = pdfBlob);

/* insert the attachment */
insert a;

/* send the user back to the quote detail page */
return controller.view();
}

 

 

 

Message Edited by JamesZ on 07-24-2009 05:04 PM
jeffdonthemicjeffdonthemic

James,

 

You should be able to get the currently selected value fairly easily. I'm not sure of the Visualforce page but you should be able to add a public member that references it from your Controller. Take a look at the link below and you should be able to figure it out. There are 3 picklists on the Visualforce page and I use their current values in the Controller.

 

Dependent Multilevel Selectlists

 

Jeff Douglas

Appirio

http://blog.jeffdouglas.com