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

Setting ownership using CreatedBy field
Hi quick question,
does anybody know if it is possible to set the ownership of a record using the CreatedBy field? Because the createdby is not populated until the record is inserted a before insert would not work, I dont think.
Is it commonplace to use an after insert to update the same record being inserted?
Thanks!
You can set OwnerId = UserInfo.getUserId();
so it will be the running user who is creating the record(created by).
All Answers
You can set OwnerId = UserInfo.getUserId();
so it will be the running user who is creating the record(created by).
Can I ask why this is needed? OwnerId is always defaulted to the Id of the creating user.
Oh ok, didn't know that either. I am still going to use Tej's recommendation though as I need to check if the current user is of a specific userrole type.