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
sdetweilsdetweil 

how to determine user during before insert trigger.

I have a field in a custom objec that needs to be set before the data is put in the database.

I want some data (custom field) from the current users record to be copied into one of the fields.

but it needs to be changable later.. (so the field can't be defined as calculated)..

 

but trigger.new.createdby  is not set in the before insert trigger..

 

how can I get access to this info?  the UserInfo object doesn't give me access to the custom fields..

 

thx for any insight

wt35wt35

I presume you can use the UserInfo.getUserId() method to retrieve the ID of the context user, then retrieve the custom fields through SOQL.

 

ID id = UserInfo.getUserId();

contextUser = [SELECT yourcustomobjects FROM User WHERE Id = :id];

sdetweilsdetweil

yes, I suppose, but I was 'hoping' for a user 'object' that I could reference the fields from.. we added fields to the user record, and these are the ones I want to get access to..

 

thanks..

 

Sam