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
Amol GujareAmol Gujare 

Pre selected division name in multiselect list

Hi :


Is there any way i can display preselected division names in list on the basis of user profile. All user can see all divison names but i want to mark as selected in the multiselectlist for couple of division names. Like in normal java code we use "Selected"


 Anyone knows what code i should use to mark those divison as pre selected.


Controller Class:


    //Method to get the division options from the Division_Information__c custom Object.
    public List<SelectOption> getDivisions()
        List<SelectOption> options = new List<SelectOption>();
        String divQry;
        String divQryAdl;
        List<Division_Information__c> divisioninfo;
        List<User_Division__c> leadDivision;

                divQry='Select u.User__c,u.Id, u.Division__r.Name,u.Division__r.Id  From User_Division__c u where user__c= \''+UserInfo.getUserId()+'\'';
            divQry+= ' and u.Division__r.is_Live__c=true'; 
            String divAdlQry=' order by u.Division__r.Name';
            String divFinalQry=divQry+divAdlQry;
            //List<Division_Information__c> leadDivision =[Select  g.Name  From Division_Information__c g order by g.Name asc];
            leadDivision =Database.query(divFinalQry);
            for( User_Division__c f : leadDivision)
                options.add(new SelectOption(f.Division__r.Name, f.Division__r.Name));
            for(Integer i =0; i < leadDivision.size() ;i++)
            for(Integer i =0; i < leadDivision.size() ;i++)
            if (leadDivision.size()==0){
                options.add(new SelectOption('No Division found', 'No Division found'));

      return options;

    public void setDivision(String[] division) { this.division = division; } 

    /* Getter for the division value */
    public String[] getDivision() {
        return division;



Visualforce Page:


               <apex:pageblockSectionItem id="division">
                    <apex:panelGrid columns="1" id="theGrid2"> 
                        <apex:outputLabel value="Division" for="pc32" styleClass="heading"/>
                            <apex:pageblockSectionItem id="divisionInput">
                                <apex:selectList value="{!Division}"  id="LeadDivision" multiselect="true" size="5" disabled="{!NoDivisionFlg}">
                                    <apex:selectOptions value="{!Divisions}"/>                        


In Apex Code, the variable represented by the value attribute of the list can be set to a specific value to provide a default. In your constructor, add the defaulted values to the List<String> Division.

Amol GujareAmol Gujare

Thank You for your response. But my i can not hardcode the value as a defaulted


Example: I am X user and i have 2 divisons assigned, then in the list box i wanted to show all divisons but 2 divisons should be marked(selected). so its utp to the user profile, how many divisions he is assigend to.


how to mark those seleted in the code.



You'll have to query the value from their profile in the constructor, and assign the value in the constructor as I've shown you.