function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi,
How can I get the list of available users, user roles and salesforce user attributes in my apex class?
Hi,You can query to get list of user as below;List<user> us=[select name,id from user ];
UserRole ur=[Select u.CaseAccessForAccountOwner, u.ForecastUserId, u.Id, u.LastModifiedById,u.LastModifiedBy.Alias, u.LastModifiedBy.CallCenterId, u.LastModifiedBy.City, u.LastModifiedBy.CompanyName, u.LastModifiedBy.ContactId, from UserRole u];
Id roleId = [select UserRoleId from User where Id = :userId].UserRoleId;Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks for the reply.
I am able to get the available users list now.
Can I get the list of all available roles in salesforce (not only available user role) as well?
To retrieve all roles, try this:
List<UserRole> lstUserRoles=[Select id,Name from UserRole];
Hope this helps.
Thanks and Regards,
Devendra S
Thank you. I am able to get the roles as well.
Similarly, Can I get the salesforce user attribute names (not values) such as username, email, firstname, lastname, etc..
Try this,
List<User> lstUser=[Select id,name,Username,Email,FirstName,LastName from User];
similary you can query for other attributes of User.
Regards,
If any of my replies/answers work for you, do mark them as 'Solution' as it may help others.
Thanks for your reply.
I need to get the user attribute names present in salesforce to search user.
Here User Id is the unique attribute to search a user in salesforce. So you can query user id and then can search in salesforce as below:
List<User> u= [select id from user where email=’abc@yahoo.com’];
You can search a user in salesforce by email, username attribute of user too.
Hi,
You can query to get list of user as below;
List<user> us=[select name,id from user ];
UserRole ur=[Select u.CaseAccessForAccountOwner, u.ForecastUserId, u.Id, u.LastModifiedById,u.LastModifiedBy.Alias, u.LastModifiedBy.CallCenterId, u.LastModifiedBy.City, u.LastModifiedBy.CompanyName, u.LastModifiedBy.ContactId, from UserRole u];
Id roleId = [select UserRoleId from User where Id = :userId].UserRoleId;
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks for the reply.
I am able to get the available users list now.
Can I get the list of all available roles in salesforce (not only available user role) as well?
To retrieve all roles, try this:
List<UserRole> lstUserRoles=[Select id,Name from UserRole];
Hope this helps.
Thanks and Regards,
Devendra S
Thank you. I am able to get the roles as well.
Similarly, Can I get the salesforce user attribute names (not values) such as username, email, firstname, lastname, etc..
Hi,
Try this,
List<User> lstUser=[Select id,name,Username,Email,FirstName,LastName from User];
similary you can query for other attributes of User.
Hope this helps.
Regards,
Devendra S
If any of my replies/answers work for you, do mark them as 'Solution' as it may help others.
Thanks for your reply.
I need to get the user attribute names present in salesforce to search user.
Hi,
Here User Id is the unique attribute to search a user in salesforce. So you can query user id and then can search in salesforce as below:
List<User> u= [select id from user where email=’abc@yahoo.com’];
You can search a user in salesforce by email, username attribute of user too.