You need to sign in to do that
Don't have an account?
Jaanu
Urgent Pls - how to get user name from salesforce id ?
I have 18 char id for the user. But I want to get the User name using the 18 char salesforce user id in Apex class. I tried to use the SOQL query to get the user name... it's exceeding the governer limits.. any other way getting the user name plase .. thanks.
You can use SOQL to retrieve the user name if you have userId. SOQL that needs to be used:
User usr = [Select name From User where Id='0056F000006eynwQAA']; //replace id with actual user id
String userName = usr.Name; //use "usr.Name" to access user name of this record
//above query will run for one user id
//if you have list of userId, you can get the user names from below query
// let's say you have list "userIDs" that has all userIds
List<User> usrs = [Select name From User where Id=: userIDs];
//get all user names using below for each loop
for(User u : usrs){
String userName = u.Name; //retrieve user name of user record
}
I hope you find the above solution helpful.If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
All Answers
If possible, if you have less users or filter condition then you can do like below, Thanks,
Govindaraj.S
Please keep this community clean by closing solved cases.
Thanks,
Govindaraj.S
You can use SOQL to retrieve the user name if you have userId. SOQL that needs to be used:
User usr = [Select name From User where Id='0056F000006eynwQAA']; //replace id with actual user id
String userName = usr.Name; //use "usr.Name" to access user name of this record
//above query will run for one user id
//if you have list of userId, you can get the user names from below query
// let's say you have list "userIDs" that has all userIds
List<User> usrs = [Select name From User where Id=: userIDs];
//get all user names using below for each loop
for(User u : usrs){
String userName = u.Name; //retrieve user name of user record
}
I hope you find the above solution helpful.If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha