You need to sign in to do that
Don't have an account?
Get ID from list to append URL
I am creating a VF page where students will choose their school from a dropdown list and then based on the selection, proceed to a registration page specific to that school. I am creating the list, grabbing the Name and ID, in a custom controller. I've the the dropdown working, but I'm stuck on how to get the ID once the school is selected and appending it to a URL so that the students are directed to the right page. Any thoughts?
My code for reference:
VF page:
And controller:
My code for reference:
VF page:
<apex:page showHeader="false" sideBar="false" standardStylesheets="false" docType="html-5.0" applyBodyTag="false" applyHtmlTag="false" controller="SDPController"> <script> </script> <apex:composition template="{!$Site.Template}"> <apex:define name="title">{!$Label.LBL_Page_Title}</apex:define> <apex:define name="body"> <div class="container"> <div align="center" style="font-size:20px;"> <p>Welcome to the Digital On-Ramps ePortfolio! Please select you school and click "Next."</p> <apex:form > <apex:selectList multiselect="false" size="1" required="false" style="font-size:20px;"> <apex:selectOptions value="{!PAIList}" /> </apex:selectList> <div class="modal-footer"> <apex:commandButton id="register" value="Next" /> </div> </apex:form> </div> </div> </apex:define> </apex:composition> </apex:page>
And controller:
public without sharing class SDPController { public List<Account> PAISchools = new List<Account>(); public SDPController(){ } public List<SelectOption> PAIList{ get{ PAISchools = [Select Account.Name, Account.Id From Account Where Account.ParentId = '0011700000BZkKR']; PAIList = new List<SelectOption>(); for(Account temp : PAISchools){ PAIList.add(new SelectOption(temp.id, temp.Name)); } return PAIList; } set; } }
Here is a simple way of doing it.
1.Create a command Button on vf page , with action = "{!saveform}"
2. Update below,
<apex:selectList multiselect="false" size="1" required="false" style="font-size:20px;" value="{!idString}">
<apex:selectOptions value="{!PAIList}" /> </apex:selectList>
2.Create a string with {get;set;} inside the controller.
public string idString {get;set;}
inside the constructor, initialize it to idString = new String();
3.Create a method inside the controller.
public pagereference saveform()
{
update object ; // helps in saving the record
PageReference pageRef = new PageReference('/apex/NEWPAGENAME?id='+idString+'');
pageRef.setRedirect(true);
return pageRef;
}
PLEASE SELECT THIS AS THE RIGHT ANSWER, IF YOU LIKE IT.
Thanks,
Rohit Alladi
All Answers
Here is a simple way of doing it.
1.Create a command Button on vf page , with action = "{!saveform}"
2. Update below,
<apex:selectList multiselect="false" size="1" required="false" style="font-size:20px;" value="{!idString}">
<apex:selectOptions value="{!PAIList}" /> </apex:selectList>
2.Create a string with {get;set;} inside the controller.
public string idString {get;set;}
inside the constructor, initialize it to idString = new String();
3.Create a method inside the controller.
public pagereference saveform()
{
update object ; // helps in saving the record
PageReference pageRef = new PageReference('/apex/NEWPAGENAME?id='+idString+'');
pageRef.setRedirect(true);
return pageRef;
}
PLEASE SELECT THIS AS THE RIGHT ANSWER, IF YOU LIKE IT.
Thanks,
Rohit Alladi