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

Hello,

I have tried below solution as you shared but getting some problem so please let me know how can fix this problem and get all users of salesforce using apex.

@RestResource(urlMapping='/User/*')
global class UserListClass{
@HttpGet global static List getUser() {

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;

}
}

Appear 3 problem let me know how we can solve this issue

One more think, Could we set a meeting for some discussion related to apex code and some other things.

If it's possible to meeting setup, please let me know.

ANUTEJANUTEJ (Salesforce Developers) 
Hi Bhavesh,

Can you try the below snippet once:
 
@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;

}
}

Also, can you please check if the soql that is used if it is proper and if it is returning the proper list of records that needs to be returned.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.