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

How do i access the the Owner(User) object in account or other standard objects?

I.e in accounts using apex i can do

Account a;


In my trigger before insert this field is always null or the owner object is always null why is that?

for(Account a : {
   a.Owner.userRoleId; //this is always null do i have to use an SOQL statement or something.
I don't think the owner is set until after the object is inserted.  you have to use afterInsert for your trigger in order to access that.  if you need to access it before hand, you need to do with from the user's session, not the object you're trying to create.
but what about before update that hsould not be null i have before insert, before update

i know on insert it should be null bu tnot when it is an update?
that i don't know.  maybe someone else will chime in with experience in that part.