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
Anass Haial 9Anass Haial 9 

UserInfo.getUserId()) retunr null ?!

We have a milestone that execute a field update, this field update trigger the Case Ater update trigger.
The trigger after update on case use the following function  :  THA_Utils.getProfileIdByName(UserInfo.getUserId());
[...]
public static string getProfileIdByName(Id isUser) {  
List<Profile> listProfile = [Select Name From Profile Where Id in (SELECT ProfileId
                                     FROM User
                                     WHERE id =:idUser)];
                                 return listProfile[0].Name;
 }
We are getting error on the   :  return listProfile[0].Name;   / caused by: System.ListException: List index out of bounds: 0: Class.THA_Utils.getProfileNameByIdUser: line 65, column 1".

Does anyone know why we have this bug ? 
the Default Workflow User is already set up as active admin... I don't udenrstand why we get this error.
Angello Camacho DragoAngello Camacho Drago
Hi Anass, can you put this in the execute anonymus of the developer console:

List<Profile> listProfile = [Select Name From Profile Where Id in (SELECT ProfileId
                                     FROM User
                                     WHERE id =:UserInfo.getUserId())];

system.debug(listProfile[0].Name);

And tell me what the log return.
Anass Haial 9Anass Haial 9
Hi Angello,

It return the name of my profile : System Admin .
 
Angello Camacho DragoAngello Camacho Drago
why don't use UserInfo.getUserId() instead idUser in the query? I think if you change it can works.