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
Bhavesh RekvarBhavesh Rekvar 

How to get all users of salesforce using apex code

Hello,

I have tried below code as you shared but there are something error so please let me know what can i do to fix this issue.

 

@RestResource(urlMapping='/User/*')
global with sharing class UserListClass{
@HttpGet 
global static List<User> getUserList() {

Map<Id,Profile> profileIds = new Map<id,profile>([SELECT Id,UserLicenseId FROM Profile where UserLicenseId  in (SELECT Id FROM UserLicense where name ='Salesforce')]);

List<user> standardProfileUsers = [select id from user where profileId in:profileIds.Keyset()];

return standardProfileUsers;

}
}

 

Blow image is appear on error screen shot so please see this issue and what can i do to fix this issue..

 

User-added image

 

Please let me know, if we can do meeting for discussion related to saleforce apex code issue...

AnudeepAnudeep (Salesforce Developers) 
Can you try initializing the list? 
 
List<User> StandardProfileUsers = new List<User>();

I don't see any issues with your code but I suggest reviewing the solution listed here

Let me know if it helps. If it does, please mark this answer as Best. It may help others in the community. Thank You!