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
sindhu@demo.comsindhu@demo.com 

How to query the logged in User?

Hi Everyone, I have a custom field "Section__c" on "User" object and "Issue" custom object.I need a trigger to fire on creation of Issue record. When a user creates a new "Issue" record assign the value of Issue_Section__c to equal the logged in user's division (user. Section__c). How to query the logged in user ??? Thanks!!!!! Regards, Prasanna
Best Answer chosen by Admin (Salesforce Developers) 
SFDC_EvolveSFDC_Evolve

 

[select id,section__c from user where id = Userinfo.getUserId().

 

All Answers

Noam.dganiNoam.dgani

in your code (trigger) you can use the System method UserInfo.getUserId().

this will give you the Id of the user running the current transaction. from there you can just perform a query on the

user table with the ID you got and select the fields relevant to you.

 

hope this helps.

if it does, please mark it as resolved.

SFDC_EvolveSFDC_Evolve

 

[select id,section__c from user where id = Userinfo.getUserId().

 

This was selected as the best answer