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
Jayesh Shewale12345Jayesh Shewale12345 

user custom field details


String userId = UserInfo.getUserId();
User u;
u=[SELECT Id, User_Pos__c FROM User WHERE Id =:userId limit 1];
 String userPos = u.User_Pos__c;

I want custom field value in my string please suggest.
Sami ShakithSami Shakith
Hello Jayesh,

How you want exactly?
Deepali KulshresthaDeepali Kulshrestha
Hi Jayesh,

In your code, if the datatype of your custom field is String then you are doing it absolutely correct. 

If the datatype of User_Pos__c field is something else then you can use the following method to convert its value into a string.

String userPos = String.valueOf(u.User_Pos__c);


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
www.kdeepali.com
Ajay K DubediAjay K Dubedi
Hi Jayesh,

Here is the correct solution to your problem. Please replace all of your above code with these lines of codes. It will work in both cases whether it is string type or another type. I hope it may help you surely.
 
String userId = UserInfo.getUserId();
    User u = new User();
    u=[SELECT Id, User_Pos__c FROM User WHERE Id =:userId limit 1];
    String userPos = String.valueOf(u.User_Pos__c);

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  (http://www.ajaydubedi.com )