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
Mor MessingMor Messing 

cannot find a user with ID that Im getting from apex error

I'm getting the below error (from an apex code) that shows a user id that I cannot find a user with that ID "0051p00000AWcQc" how is this possible? 

looked in the user list (non-active also) and ther is no such user in this org. 

Apex script unhandled trigger exception by user/organization: 0051p00000AWcQc/00D24000000JGdl
 
Best Answer chosen by Mor Messing
Team NubesEliteTeam NubesElite
Hi Mor,
First of all your code must be written in this way:
Id myId = UserInfo.getUserId(); 
List<User> me = [SELECT Id, Name, Email, Profile.Id, Profile.Name FROM User WHERE Id=:myId]; 
if(me.size()>0) {
 // Do something 
} else
 { 
// show error message. Halt the process, throw exception
 }
Above approach will never throw the error: Please try this code.



Thank You
www.nubeselite.com

Developement | Training | Consulting

Please mark this as solution if your problem resolved.

All Answers

Team NubesEliteTeam NubesElite
Hi Mor,
First of all your code must be written in this way:
Id myId = UserInfo.getUserId(); 
List<User> me = [SELECT Id, Name, Email, Profile.Id, Profile.Name FROM User WHERE Id=:myId]; 
if(me.size()>0) {
 // Do something 
} else
 { 
// show error message. Halt the process, throw exception
 }
Above approach will never throw the error: Please try this code.



Thank You
www.nubeselite.com

Developement | Training | Consulting

Please mark this as solution if your problem resolved.
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Mor,

Use this code helpful for you.
 
List<User> userList = New List<User>();
userList = [Select Id,Name From user Where Id =:'UserId(You define)'];
if(userList.Size() > 0){
    System.debug('userList==>'+userList); // Show user Id and Name
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com