+ Start a Discussion
Luffy Carl_opLuffy Carl_op 

How can I get current user's custom field, not the standard field.

For example, if i add a custom field "myposition", how can i get it in apex class?
UserInfo.getMyposition()  or  UserInfo.myposition  are both invalid.
Best Answer chosen by Luffy Carl_op
benedwards44benedwards44

The only supported methods for the UserInfo class are those in the documentation:

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_userinfo.htm

If you want to get custom fields from the user object, you will have to do a SOQL query. Eg:

String myPosition = [Select My_Position__c From User Where Id = :UserInfo.getUserId()][0].My_Position__c;

All Answers

benedwards44benedwards44

The only supported methods for the UserInfo class are those in the documentation:

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_userinfo.htm

If you want to get custom fields from the user object, you will have to do a SOQL query. Eg:

String myPosition = [Select My_Position__c From User Where Id = :UserInfo.getUserId()][0].My_Position__c;
This was selected as the best answer
Luffy Carl_opLuffy Carl_op
It's wonderful. I don't know if benedwards44 could see my thanks, but i still want to say thanks to you. I have been confused by this problem. thanks.