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
SurenderSurender 

Requirement to store User names in an String array with iterating these 20 records

Hi,

 


I have SOQL which retrieves 20 User records. I have a requirement to store User names in an String array with iterating these 20 records.


Can someone reply on how to accomplish this.

 

Thanks in advance.

 

 

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet as Reference:

 

List<User> us=new List<User>();

us=[Select id,Name from User];

List<String> usernamestr=new List<String>();

for(User u:us)

{

    usernamestr.add(u.name);

}

for(String strnme:usernamestr)

{             

                  system.debug('______each user in loop________'+strnme);

}

  

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.