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
Liz Gibbons 16Liz Gibbons 16 

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:
<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;    
    }
  
        
}

 
Best Answer chosen by Liz Gibbons 16
RohRoh
Hello Liz Gibbons 16,
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

RohRoh
Hello Liz Gibbons 16,
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
This was selected as the best answer
Liz Gibbons 16Liz Gibbons 16
Thank you, Rohit! That has it working.