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
SabrentSabrent 

Passing List of Users to a picklist and displaying it in lightning component

<aura:component  controller = "EmailViewController">
    
    <aura:attribute name="userList" type="User[]"/> 
    <aura:handler name="init" value="{!this}" action="{!c.pickUser}"/>

    <lightning:combobox name="general" label="Many Options" 
               placeholder="Select a User Option" options{!v.userList}" onchange="{! c.pickUser}"/>
   
</aura:component>

<.JS controller>

pickUser: function (component, event, helper) {
        var action = component.get("c.getUsers");
        action.setCallback(this, function(response){
                var state = response.getState();
                if (state === "SUCCESS") {
                    var listItems = response.getReturnValue();
                    component.set("v.userList", listItems);
                }
        });
        
        $A.enqueueAction(action);
    }


<Apex Controller>

@AuraEnabled
	public static List<User> getUsers()
	{
		List<User> lstUsers = [SELECT Id,FirstName,LastName FROM User];

		return lstUsers;
	}

Can some one please check my coode and tell me why my picklist in the lightning cmponent is not populating with anu values? 

Basiclaly on my lightning component I want a picklist of Users. 

Thanks !
Raj VakatiRaj Vakati
Chane your code as below
 
<aura:component  controller = "EmailViewController">
    
    <aura:attribute name="userList" type="String[]"/> 
    <aura:handler name="init" value="{!this}" action="{!c.pickUser}"/>

    <lightning:combobox name="general" label="Many Options" 
               placeholder="Select a User Option" options{!v.userList}" onchange="{! c.pickUser}"/>
   
</aura:component>
 
pickUser: function (component, event, helper) {
        var action = component.get("c.getUsers");
        action.setCallback(this, function(response){
                var state = response.getState();
                if (state === "SUCCESS") {
                    var listItems = response.getReturnValue();
                    component.set("v.userList", listItems);
                }
        });
        
        $A.enqueueAction(action);
    }
 
@AuraEnabled
	public static List<String> getUsers()
	{
		List<User> lstUsers = [SELECT Id,FirstName,LastName FROM User];
       List<String> userList = new List<String>();
		for(User u : lstUsers){
			userList.add(u.UserName) ;
		}
			
		return userList;
	}

 
SabrentSabrent
Illegal conversion from list to list error when compiling Apex controller
Raj VakatiRaj Vakati
@AuraEnabled
	public static List<String> getUsers()
	{
		List<User> lstUsers = [SELECT Id,FirstName,LastName FROM User];
       List<String> userList = new List<String>();
		for(User u : lstUsers){
			userList.add(u.UserName) ;
		}
			
		return userList;
	}
This method is working for me .. are you getting error from the same method or differnt merthod
 
SabrentSabrent
Same method. I fail to understand why the error. 
That's the reason i just returned the list as is, instead of converting it to list of string, and returning that instead. 
Raj VakatiRaj Vakati
Check is there any apex class with the name LIST 
SabrentSabrent
There are no classes with the name List
mohd areeb 8mohd areeb 8
how we can achieve this in LWC