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
lodoss118lodoss118 

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;

a.Owner.UserRoleId;

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

for(Account a : trigger.new) {
   a.Owner.userRoleId; //this is always null do i have to use an SOQL statement or something.
}
paul-lmipaul-lmi
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.
lodoss118lodoss118
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?
paul-lmipaul-lmi
that i don't know.  maybe someone else will chime in with experience in that part.