+ Start a Discussion
dhubbarddhubbard 

Page routing based on field input

I'm having trouble finding out if this is even possible, let alone how to go about it. 

 

I have a VF page built for lead entering by staff that are not Salesforce users. I need to set it up so when they enter a specific field (employee size) for a company, it routes them to different pages based on that field. Thera are 3 different processes based on that, so I need it to go to one of 3 pages when they hit Save.

 

Any ideas or thoughts would be appreciated. I'm sure there's something I just haven't thought of yet.

 

Thanks!! 

SteveBowerSteveBower

I'm assuming you have a controller built for your page.

 

If so, when your controller actions return, they should be returning something of type pageReference.  So, you can do something like:

 

 

public pageReference doSave() {

// Do whatever saving logic you have here, etc.

// ....

 

// Return to a different apex page depending on employee count.

pageReference p;

if (employeeSize < 10) {

     p = new pageReference('/apex/the_page_for_small_businesses');

else if (employeeSize < 100) {

     p = new pageReference('/apex/the_page_for_medium');

else {

     p = new pageReference('whatever URLs you need for the various processes go here: /apex/the_page_for_large');

}

p.setRedirect(true);

return p;

}

 

Hope this helps, Steve.

dhubbarddhubbard
Thanks! I'll give that a shot in the morning.
dhubbarddhubbard

I've built an extension for this, but I'm getting an error: Error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, Integer at line 15 column 5

 

Here's the code as it stands, any ideas?

public class clubleadSave{ public clubleadSave() { } ApexPages.StandardController controller; public clubleadSave(ApexPages.StandardController con){ controller = con; } public PageReference save() { controller.save(); // Return to a different apex page depending on employee count. pageReference p; if (Lead.NumberOfEmployees<50) { p = new pageReference('/apex/SmallBusinessProcess'); } else if (Lead.NumberOfEmployees< 250) { p = new pageReference('/apex/MediumBusinessProcess'); }else { p = new pageReference('/apex/LeadSubmitted'); } p.setRedirect(true); return p; } }

 

SteveBowerSteveBower

How is "Lead" defined in your code?   

 

I think it's using "Lead.NumberOfEmployees" in the sense of a Field Token as oppposed to what you want which is a field in a local variable.   Look into Describe stuff in Apex.

 

Somewhere in your code you should have something like:

 

Lead myLead;

// and perhaps getters and setters

and then use   if (myLead.NumberOfEmployees > 50) ... etc.

 

Best, Steve.