Approval Class
Contains methods for processing approval requests and setting approval-process locks and unlocks on records.
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
trueif the record with the IDidis locked, orfalseif it’s not. -
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 isfalse. -
Returns
trueif thesobjectrecord is locked, orfalseif it’s not. -
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 isfalse. -
Locks an object, and returns the lock results.
-
Locks a set of objects, and returns the lock results, including failures.
-
Locks an object, and returns the lock results.
-
Locks a set of objects, and returns the lock results, including failures.
-
Locks an object, with the option for partial success, and returns the lock result.
-
Locks a set of objects, with the option for partial success. It returns the lock results, including failures.
-
lock(recordToLock, allOrNothing)
Locks an object, with the option for partial success, and returns the lock result.
-
lock(recordsToLock, allOrNothing)
Locks a set of objects, with the option for partial success. It returns the lock results, including failures.
-
Submits a new approval request and approves or rejects existing approval requests.
-
process(approvalRequest, allOrNone)
Submits a new approval request and approves or rejects existing approval requests.
-
Submits a list of new approval requests, and approves or rejects existing approval requests.
-
process(approvalRequests, allOrNone)
Submits a list of new approval requests, and approves or rejects existing approval requests.
-
Unlocks an object, and returns the unlock results.
-
Unlocks a set of objects, and returns the unlock results, including failures.
-
Unlocks an object, and returns the unlock results.
-
Unlocks a set of objects, and returns the unlock results, including failures.
-
unlock(recordId, allOrNothing)
Unlocks an object, with the option for partial success, and returns the unlock result.
-
unlock(recordIds, allOrNothing)
Unlocks a set of objects, with the option for partial success. It returns the unlock results, including failures.
-
unlock(recordToUnlock, allOrNothing)
Unlocks an object, with the option for partial success, and returns the unlock result.
-
unlock(recordsToUnlock, allOrNothing)
Unlocks a set of objects, with the option for partial success. It returns the unlock results, including failures.
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)
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)
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)
Type: List<Approval.LockResult>
Locks an object, and returns the lock results.
public static Approval.LockResult lock(SObject recordToLock)
- recordToLock: Type: SObject
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
falseand 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
falseand 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
falseand 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
falseand 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)
- approvalRequest: Type: Approval.ProcessRequest
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
falsefor this parameter and an approval fails, the remainder of the approval processes can still succeed.
Submits a list of new approval requests, and approves or rejects existing approval requests.
public static Approval.ProcessResult [] process(Approval.ProcessRequest[] approvalRequests)
- approvalRequests: Approval.ProcessRequest []
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
falsefor this parameter and an approval fails, the remainder of the approval processes can still succeed.
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)
Type: List<Approval.UnlockResult>
Unlocks an object, and returns the unlock results.
public static Approval.UnlockResult unlock(SObject recordToUnlock)
- recordToUnlock: Type: SObject
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
falseand 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
falseand 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
falseand 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
falseand 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>