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
V100V100 

Selected List and using the value selected

Looking to use a VF page to display as a select list all profiles on the org and allow them to be selected into a custom object.

The display of profile all works fine, however when i try to add the value:

jProfile, it returns nothing.

selectedProfilesit returns Null.

 

Any suggestions as to where i am going wrong? Thanks

 

VF

    <apex:pageBlock id="block">
    <apex:pageMessages />          
        <apex:pageBlockSection title="Add Rule" id="section1">
<apex:pageBlockSectionItem id="selProfile"> <apex:outputLabel value="Profile"/> <apex:selectList value="{!selectedProfiles}" size="1" id="ProfilesSelect"> <apex:selectOptions value="{!Profiles}"/> </apex:selectList> </apex:pageBlockSectionItem>

        <apex:commandButton value="Create New Rule" action="{!addRule}" reRender="block" immediate="true">
        <apex:param name="jmProfile" value="{!selectedProfiles}" assignTo="{!jProfile}"/>
        </apex:commandButton>

 Controller

    private List<SelectOption> Profiles;
    
    public List<String> selectedProfiles {get; set;}
    public String jProfile {get;set;} 
    
    public List<SelectOption> getProfiles() {
      Profiles = new List<SelectOption>();
      Profiles.add(new SelectOption('None', 'None'));
      for (Profile rt : [Select Id, Name 
                            From Profile 
                            Order By Name ASC]) {                 
        Profiles.add(new SelectOption(rt.Name, rt.Name));
      }
      return Profiles;
    }

 

Best Answer chosen by Admin (Salesforce Developers) 
sivaextsivaext

Hi

 

you slightly change code like this,

Page:

 

<apex:pageBlock id="block">
<apex:pageMessages />
<apex:pageBlockSection title="Add Rule" id="section1">
<apex:pageBlockSectionItem id="selProfile">
<apex:outputLabel value="Profile"/>
<apex:selectList value="{!selectedProfiles}" size="1" id="ProfilesSelect">
<apex:selectOptions value="{!Profiles}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:commandButton value="Create New Rule" action="{!addRule}" >
<!-- <apex:param name="jmProfile" value="{!selectedProfiles}" assignTo="{!jProfile}"/> -->
</apex:commandButton>
</apex:pageBlock>
</apex:form>

 

controller :

 

private List<SelectOption> Profiles;

public String selectedProfiles {get; set;}


public PageReference addRule() {

system.debug('..............'+selectedProfiles );

 

//The selectedProfiles written selected value, Use that perform what do you want
return null;
}




public List<SelectOption> getProfiles () {
Profiles = new List<SelectOption>();
Profiles.add(new SelectOption('None', 'None'));
for (Profile rt : [Select Id, Name
From Profile
Order By Name ASC]) {
Profiles.add(new SelectOption(rt.Name, rt.Name));
}
return Profiles;
}

All Answers

Mohith Kumar ShrivastavaMohith Kumar Shrivastava

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_selectList.htm

 

Have a look at the document once more .

 

Onething i noticed is you have multiselect equal to false and hence as shown below use a String variable not an array please.

 

public String selectedProfiles {get; set;}

 

sivaextsivaext

Hi

 

you slightly change code like this,

Page:

 

<apex:pageBlock id="block">
<apex:pageMessages />
<apex:pageBlockSection title="Add Rule" id="section1">
<apex:pageBlockSectionItem id="selProfile">
<apex:outputLabel value="Profile"/>
<apex:selectList value="{!selectedProfiles}" size="1" id="ProfilesSelect">
<apex:selectOptions value="{!Profiles}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:commandButton value="Create New Rule" action="{!addRule}" >
<!-- <apex:param name="jmProfile" value="{!selectedProfiles}" assignTo="{!jProfile}"/> -->
</apex:commandButton>
</apex:pageBlock>
</apex:form>

 

controller :

 

private List<SelectOption> Profiles;

public String selectedProfiles {get; set;}


public PageReference addRule() {

system.debug('..............'+selectedProfiles );

 

//The selectedProfiles written selected value, Use that perform what do you want
return null;
}




public List<SelectOption> getProfiles () {
Profiles = new List<SelectOption>();
Profiles.add(new SelectOption('None', 'None'));
for (Profile rt : [Select Id, Name
From Profile
Order By Name ASC]) {
Profiles.add(new SelectOption(rt.Name, rt.Name));
}
return Profiles;
}

This was selected as the best answer
V100V100

Thanks for the help, couldnt see  the problem for looking at it!