You need to sign in to do that
Don't have an account?

Retrieve userId without SOQL in apex class
Hi,
I am having a problem that should be really easy to solve. It's easy to retrieve a user id in a trigger or class using soql. But I am hitting a soql 101 limit error and thus need to have my code run some of one of my trigger when a specific user creates a record. I can also do this by simply hardcoding the user's id in the trigger, but I don't want to do that.
Basically the algorithm is: trigger on object x updates a few fields on a record after it is interted, but only when user "a" creates the record. The trigger should simply call a class that updates some fields on that newly inserted record by that specific user. The trick is, in the trigger, specify the user who should be allowed to call that class without hardcoding the user's ID.
Basically what I need is a utiluty class I can call that returns the userId of the current user based on his/her alias or username. Any ideas?
I am having a problem that should be really easy to solve. It's easy to retrieve a user id in a trigger or class using soql. But I am hitting a soql 101 limit error and thus need to have my code run some of one of my trigger when a specific user creates a record. I can also do this by simply hardcoding the user's id in the trigger, but I don't want to do that.
Basically the algorithm is: trigger on object x updates a few fields on a record after it is interted, but only when user "a" creates the record. The trigger should simply call a class that updates some fields on that newly inserted record by that specific user. The trick is, in the trigger, specify the user who should be allowed to call that class without hardcoding the user's ID.
Basically what I need is a utiluty class I can call that returns the userId of the current user based on his/her alias or username. Any ideas?
Just use this
//Returns current logged in user Id
UserInfo.getUserId();
Regards,
Abhi Tripathi
Salesforce Developer