I cannot seem to find the documentation anywhere about this doubt. Whenever and wherever I call "Userinfo.getUserId()" method in the transaction, will it always return 18 digit user ID to me? or it varies?
1 Answer
From my observation, UserInfo.getUserId should always return an 18-character ID. However, the return type is "String" for this method, so there is no guarantee that the return value will always be the 18-character ID format. However, you can guarantee that an ID will always be 18-characters if you use the Id data type:
Id userId = UserInfo.getUserId();
This works because the Id type automatically validates the String is a valid ID and automatically calculates the parity bits for the ID (the last three characters).