+ Start a Discussion
kfm2012kfm2012 

Get Logged in User Id from with Apex Trigger

I have the following test Apex trigger on the Case Object.

 

trigger setCaseOwner on Case (before Insert)
{
Case x = trigger.new[0];

x.Description = 'TRIGGER FIRED' + User.Id ;
}

 

I'm trying to get the ID or Alias of the logged in user.  The script below displays TRIGGER FIREDId in the description field of the Case after saving.  I've also tried 'TRIGGER FIRED' + $User.Id and 'TRIGGER FIRED' + x.$User.Id which gives me syntax errors.  what's the easiest way to get information about the logged in user from within an Apex Trigger?

thx

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sai.sfsai.sf

string uid = userinfo.getUserId();

All Answers

sai.sfsai.sf

string uid = userinfo.getUserId();

This was selected as the best answer
kfm2012kfm2012

thx!