You need to sign in to do that
Don't have an account?

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()
{
divisionIds='';
divisionName='';
List<SelectOption> options = new List<SelectOption>();
String divQry;
String divQryAdl;
List<Division_Information__c> divisioninfo;
List<User_Division__c> leadDivision;
System.debug('isDivisionActive>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'+isDivisionActive);
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()+'\'';
if(isDivisionActive){
divQry+= ' and u.Division__r.is_Live__c=true';
}
String divAdlQry=' order by u.Division__r.Name';
String divFinalQry=divQry+divAdlQry;
System.debug('divFinalQry>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'+divFinalQry);
//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));
divisionList.add(f.Division__r.Id);
}
System.debug('leadDivision.size()>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'+leadDivision.size());
for(Integer i =0; i < leadDivision.size() ;i++)
{
divisionName=divisionName+'\''+leadDivision[i].Division__r.Name+'\'';
if(i<leadDivision.size()-1)
divisionName=divisionName+',';
}
for(Integer i =0; i < leadDivision.size() ;i++)
{
divisionIds=divisionIds+'\''+leadDivision[i].Division__r.Id+'\'';
if(i<leadDivision.size()-1)
divisionIds=divisionIds+',';
}
if (leadDivision.size()==0){
options.add(new SelectOption('No Division found', 'No Division found'));
noDivisionFlg=true;
}
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}"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:panelGrid>
</apex:pageblockSectionItem>
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.
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.