-2

I am having a multiselect picklist in that am displaying the list of profiles in the org using SOQL Query.My usecase is like when i click on any profile/profiles those related applications should be displayed in another dropdown

I have a SOQL query to fetch the list of applications in the org but i am not sure how to render the profile related application in a dropdown dynamically.Any help would be appriciated

This is how i am querying the application

  public List<SelectOption> getApps()
 {
   List<String> profileName = new List<String>();
   List<AppMenuItem> apps= [ SELECT Name FROM AppMenuItem WHERE Type = 'TabSet' ];
  list<SelectOption>  lstOptions = new list<SelectOption>();
  for(AppMenuItem app: apps){
      lstOptions.add(new SelectOption(app.Name,app.Name));
  }
  return lstOptions;

}

1

You just need to have variables or methods to calculate what the values should be. Here's an example that should work in any org. You'll want to read more about apex:actionSupport in the documentation.


public class q249304 {
    public Id[] profileIds { get; set; }
    public Id[] userIds { get; set; }

    // Renders a list of options for profiles
    public SelectOption[] getProfiles() {
        SelectOption[] results = new SelectOption[0];
        for(Profile record: [SELECT Name FROM Profile ORDER BY Name]) {
            results.add(new SelectOption(record.Id, record.Name));
        }
        return results;
    }
    // Renders a list of users that have the selected profiles, if any
    public SelectOption[] getUsers() {
        SelectOption[] results = new SelectOption[0];
        if(profileIds != null) {
            for(User record:[SELECT Name FROM User WHERE ProfileId = :profileIds ORDER BY Name]) {
                results.add(new SelectOption(record.Id, record.Name));
            }
        }
        return results;
    }
}

<apex:page controller="q249304">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection columns="1">
                <apex:selectList label="Profiles" multiselect="true" value="{!profileIds}" size="5">
                    <apex:selectOptions value="{!profiles}" />
                    <apex:actionSupport event="onchange" reRender="users" />
                </apex:selectList>
                <apex:selectList id="users" label="User" multiselect="true" value="{!userIds}" size="5">
                    <apex:selectOptions value="{!users}" />
                    <apex:actionSupport event="onchange" reRender="userList" />
                </apex:selectList>
            </apex:pageBlockSection>
            <apex:pageBlockSection id="userList">
                Selected Users: {!userIds}
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.