Is it possible to change the owner of the record through APEX even though the user that executing the apex code is not the owner or system admin?

1 Answer 1


Yes, its possible if you write your class without sharing.

Without sharing keyword make sure that code runs in system context and so it has full access to change the ownership of record even if current user id not the owner.

Here is sample code that should give you idea.

  public without sharing class noSharing {
        public static void changeOwner(Account acc, User us){
             acc.OwnerId = us.Id;
             update acc;

Here are more details on without sharing https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .