Skip to content

Commit

Permalink
Added ability to 'elevateContext' inside a Unit of Work
Browse files Browse the repository at this point in the history
Allows writing of records to which the user does not have write access.
  • Loading branch information
rob-baillie-ortoo committed Dec 12, 2021
1 parent 04128c9 commit 44dc4e7
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,40 @@ public inherited sharing class ortoo_SobjectUnitOfWork extends fflib_SObjectUnit
super( sObjectTypes, dml );
}

/**
* Provides an elevated context for calls to the Unit of Work.
*
* Specifically, removes sharing from the call meaning that the Unit of Work can commit
* records that the current user would not normally have write access to.
*
* @return ortoo_SobjectUnitOfWork.ElevatedContext The elevated context against which a commit can be issued
*/
public ElevatedContext elevatedContext()
{
return new ElevatedContext( this );
}

/**
* Provides the ability to remove sharing rules from the current context
*/
public without sharing class ElevatedContext
{
ortoo_SobjectUnitOfWork uow;

public ElevatedContext( ortoo_SobjectUnitOfWork uow )
{
this.uow = uow;
}

/**
* Commit the currently queued work, not applying sharing rules when that is done.
*/
public void commitWork()
{
uow.commitWork();
}
}

/**
* Returns the number of DML rows that are pending for this Unit of Work
*
Expand Down

0 comments on commit 44dc4e7

Please sign in to comment.