Approval Class

Contains methods for processing approval requests and setting approval-process locks and unlocks on records.

System

Salesforce admins can edit locked records. Depending on your approval process configuration settings, an assigned approver can also edit locked records. Locks and unlocks that are set programmatically use the same record editability settings as other approval-process locks and unlocks.

Record locks and unlocks are treated as DML. They’re blocked before a callout, they count toward your DML limits, and if a failure occurs, they’re rolled back along with the rest of your transaction. To change this rollback behavior, use an allOrNone parameter.

Approval is also used as a namespace for the ProcessRequest and ProcessResult classes.

See Also

The following are methods for Approval. All methods are static.

Returns true if the record with the ID id is locked, or false if it’s not.

public static Boolean isLocked(Id id)

  • id: Type: Id The ID of the record whose lock or unlock status is in question.

Type: Boolean

Returns a map of record IDs and their lock statuses. If the record is locked the status is true. If the record is not locked the status is false.

public static Map<Id,Boolean> isLocked(List<Id> ids)

  • ids: Type: List<Id> The IDs of the records whose lock or unlock statuses are in question.

Type: Map<Id,Boolean>

Returns true if the sobject record is locked, or false if it’s not.

public static Boolean isLocked(SObject sobject)

  • sobject: Type: SObject The record whose lock or unlock status is in question.

Type: Boolean

Returns a map of record IDs to lock statuses. If the record is locked the status is true. If the record is not locked the status is false.

public static Map<Id,Boolean> isLocked(List<SObject> sobjects)

  • sobjects: Type: List<SObject> The records whose lock or unlock statuses are in question.

Type: Map<Id,Boolean>

Locks an object, and returns the lock results.

public static Approval.LockResult lock(Id recordId)

  • recordId: Type: Id ID of the object to lock.

Type: Approval.LockResult

Locks a set of objects, and returns the lock results, including failures.

public static List<Approval.LockResult> lock(List<Id> ids)

  • ids: Type: List<Id> IDs of the objects to lock.

Type: List<Approval.LockResult>

Locks an object, and returns the lock results.

public static Approval.LockResult lock(SObject recordToLock)

Type: Approval.LockResult

Locks a set of objects, and returns the lock results, including failures.

public static List<Approval.LockResult> lock(List<SObject> recordsToLock)

Type: List<Approval.LockResult>

Locks an object, with the option for partial success, and returns the lock result.

public static Approval.LockResult lock(Id recordId, Boolean allOrNothing)

  • recordId: Type: Id ID of the object to lock.
  • allOrNothing: Type: Boolean Specifies whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that you can use to verify which records succeeded, which failed, and why.

Type: Approval.LockResult

Locks a set of objects, with the option for partial success. It returns the lock results, including failures.

public static List<Approval.LockResult> lock(List<Id> recordIds, Boolean allOrNothing)

  • recordIds: Type: List<Id> IDs of the objects to lock.
  • allOrNothing: Type: Boolean Specifies whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that you can use to verify which records succeeded, which failed, and why.

Type: List<Approval.LockResult>

Locks an object, with the option for partial success, and returns the lock result.

public static Approval.LockResult lock(SObject recordToLock, Boolean allOrNothing)

  • recordToLock: Type: SObject
  • allOrNothing: Type: Boolean Specifies whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that you can use to verify which records succeeded, which failed, and why.

Type: Approval.LockResult

Locks a set of objects, with the option for partial success. It returns the lock results, including failures.

public static List<Approval.LockResult> lock(List<SObject> recordsToLock, Boolean allOrNothing)

  • recordsToLock: Type: List<SObject>
  • allOrNothing: Type: Boolean Specifies whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that you can use to verify which records succeeded, which failed, and why.

Type: List<Approval.LockResult>

Submits a new approval request and approves or rejects existing approval requests.

public static Approval.ProcessResult process(Approval.ProcessRequest approvalRequest)

Type: Approval.ProcessResult

Submits a new approval request and approves or rejects existing approval requests.

public static Approval.ProcessResult process(Approval.ProcessRequest approvalRequest, Boolean allOrNone)

  • approvalRequest: Approval.ProcessRequest
  • allOrNone: Type: Boolean The optional allOrNone parameter specifies whether the operation allows for partial success. If you specify false for this parameter and an approval fails, the remainder of the approval processes can still succeed.

Approval.ProcessResult

Submits a list of new approval requests, and approves or rejects existing approval requests.

public static Approval.ProcessResult [] process(Approval.ProcessRequest[] approvalRequests)

Approval.ProcessResult []

Submits a list of new approval requests, and approves or rejects existing approval requests.

public static Approval.ProcessResult [] process(Approval.ProcessRequest[] approvalRequests, Boolean allOrNone)

  • approvalRequests: Approval.ProcessRequest []
  • allOrNone: Type: Boolean The optional allOrNone parameter specifies whether the operation allows for partial success. If you specify false for this parameter and an approval fails, the remainder of the approval processes can still succeed.

Approval.ProcessResult []

Unlocks an object, and returns the unlock results.

public static Approval.UnlockResult unlock(Id recordId)

  • recordId: Type: Id ID of the object to unlock.

Type: Approval.UnlockResult

Unlocks a set of objects, and returns the unlock results, including failures.

public static List<Approval.UnlockResult> unlock(List<Id> recordIds)

  • recordIds: Type: List<Id> IDs of the objects to unlock.

Type: List<Approval.UnlockResult>

Unlocks an object, and returns the unlock results.

public static Approval.UnlockResult unlock(SObject recordToUnlock)

Type: Approval.UnlockResult

Unlocks a set of objects, and returns the unlock results, including failures.

public static List<Approval.UnlockResult> unlock(List<SObject> recordsToUnlock)

Type: List<Approval.UnlockResult>

Unlocks an object, with the option for partial success, and returns the unlock result.

public static Approval.UnlockResult unlock(Id recordId, Boolean allOrNothing)

  • recordId: Type: Id ID of the object to lock.
  • allOrNothing: Type: Boolean Specifies whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that you can use to verify which records succeeded, which failed, and why.

Type: Approval.UnlockResult

Unlocks a set of objects, with the option for partial success. It returns the unlock results, including failures.

public static List<Approval.UnlockResult> unlock(List<Id> recordIds, Boolean allOrNothing)

  • recordIds: Type: List<Id> IDs of the objects to unlock.
  • allOrNothing: Type: Boolean Specifies whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that you can use to verify which records succeeded, which failed, and why.

Type: List<Approval.UnlockResult>

Unlocks an object, with the option for partial success, and returns the unlock result.

public static Approval.UnlockResult unlock(SObject recordToUnlock, Boolean allOrNothing)

  • recordToUnlock: Type: SObject
  • allOrNothing: Type: Boolean Specifies whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that you can use to verify which records succeeded, which failed, and why.

Type: Approval.UnlockResult

Unlocks a set of objects, with the option for partial success. It returns the unlock results, including failures.

public static List<Approval.UnlockResult> unlock(List<SObject> recordsToUnlock, Boolean allOrNothing)

  • recordsToUnlock: Type: List<SObject>
  • allOrNothing: Type: Boolean Specifies whether this operation allows partial success. If you specify false and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that you can use to verify which records succeeded, which failed, and why.

Type: List<Approval.UnlockResult>