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
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!