Newer Version Available
Approval Class
Namespace
Usage
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.
Approval Methods
The following are methods for Approval. All methods are static.
isLocked(ids)
isLocked(sobjects)
lock(recordId)
Signature
public static Approval.LockResult lock(Id recordId)
Parameters
- recordId
- Type: Id
- ID of the object to lock.
Return Value
Type: Approval.LockResult
lock(recordIds)
Signature
public static List<Approval.LockResult> lock(List<Id> ids)
Return Value
Type: List<Approval.LockResult>
lock(recordToLock)
Signature
public static Approval.LockResult lock(SObject recordToLock)
Parameters
- recordToLock
- Type: SObject
Return Value
Type: Approval.LockResult
lock(recordsToLock)
Signature
public static List<Approval.LockResult> lock(List<SObject> recordsToLock)
Return Value
Type: List<Approval.LockResult>
lock(recordId, allOrNothing)
Signature
public static Approval.LockResult lock(Id recordId, Boolean allOrNothing)
Parameters
- 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.
Return Value
Type: Approval.LockResult
lock(recordIds, allOrNothing)
Signature
public static List<Approval.LockResult> lock(List<Id> recordIds, Boolean allOrNothing)
Parameters
- 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.
Return Value
Type: List<Approval.LockResult>
lock(recordToLock, allOrNothing)
Signature
public static Approval.LockResult lock(SObject recordToLock, Boolean allOrNothing)
Parameters
- 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.
Return Value
Type: Approval.LockResult
lock(recordsToLock, allOrNothing)
Signature
public static List<Approval.LockResult> lock(List<SObject> recordsToLock, Boolean allOrNothing)
Parameters
- 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.
Return Value
Type: List<Approval.LockResult>
process(approvalRequest)
Signature
public static Approval.ProcessResult process(Approval.ProcessRequest approvalRequest)
Parameters
- approvalRequest
- Type: Approval.ProcessRequest
Return Value
Type: Approval.ProcessResult
Example
1// Insert an account
2
3Account a = new Account(Name='Test',
4 annualRevenue=100.0);
5
6insert a;
7
8// Create an approval request for the account
9Approval.ProcessSubmitRequest req1 =
10 new Approval.ProcessSubmitRequest();
11req1.setObjectId(a.id);
12
13// Submit the approval request for the account
14Approval.ProcessResult result =
15 Approval.process(req1);process(approvalRequest, allOrNone)
Signature
public static Approval.ProcessResult process(Approval.ProcessRequest approvalRequest, Boolean allOrNone)
Parameters
- 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.
Return Value
process(approvalRequests)
Signature
public static Approval.ProcessResult [] process(Approval.ProcessRequest[] approvalRequests)
Parameters
- approvalRequests
- Approval.ProcessRequest []
Return Value
process(approvalRequests, allOrNone)
Signature
public static Approval.ProcessResult [] process(Approval.ProcessRequest[] approvalRequests, Boolean allOrNone)
Parameters
- 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.
Return Value
unlock(recordId)
Signature
public static Approval.UnlockResult unlock(Id recordId)
Parameters
- recordId
- Type: Id
- ID of the object to unlock.
Return Value
Type: Approval.UnlockResult
unlock(recordIds)
Signature
public static List<Approval.UnlockResult> unlock(List<Id> recordIds)
Return Value
Type: List<Approval.UnlockResult>
unlock(recordToUnlock)
Signature
public static Approval.UnlockResult unlock(SObject recordToUnlock)
Parameters
- recordToUnlock
- Type: SObject
Return Value
Type: Approval.UnlockResult
unlock(recordsToUnlock)
Signature
public static List<Approval.UnlockResult> unlock(List<SObject> recordsToUnlock)
Return Value
Type: List<Approval.UnlockResult>
unlock(recordId, allOrNothing)
Signature
public static Approval.UnlockResult unlock(Id recordId, Boolean allOrNothing)
Parameters
- 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.
Return Value
Type: Approval.UnlockResult
unlock(recordIds, allOrNothing)
Signature
public static List<Approval.UnlockResult> unlock(List<Id> recordIds, Boolean allOrNothing)
Parameters
- 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.
Return Value
Type: List<Approval.UnlockResult>
unlock(recordToUnlock, allOrNothing)
Signature
public static Approval.UnlockResult unlock(SObject recordToUnlock, Boolean allOrNothing)
Parameters
- 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.
Return Value
Type: Approval.UnlockResult
unlock(recordsToUnlock, allOrNothing)
Signature
public static List<Approval.UnlockResult> unlock(List<SObject> recordsToUnlock, Boolean allOrNothing)
Parameters
- 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.
Return Value
Type: List<Approval.UnlockResult>