---
schema_version: "1"
id: b6cfb7d67fb42ece507d03ea7f89a2a766e420111b5b60184f0a8397823cf184
title: LockResult Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_Approval_LockResult.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Approval_LockResult.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 3b014b9442d08156511dc7d44002b2ddb60084330650fe8a98e27e743af08a34
description: The result of a record lock returned by a System.Approval.lock() method.If an error occurred, returns an array of one or more database error objects, providing the error code and description.Returns the ID of the sObject you are trying to lock.A Boolean value that is set to true if the lock operation is successful for this object, or false otherwise.
---
# LockResult Class

The result of a record lock returned by a System.Approval.lock() method.

## Namespace

[Approval](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Approval.htm "The Approval namespace provides classes and methods for approval processes.")

## Usage

The System.Approval.lock() methods return Approval.LockResult objects. Each element in a LockResult array corresponds to an element in the ID or sObject array passed as a parameter to a lock method. The first element in the LockResult array corresponds to the first element in the ID or sObject array, the second element corresponds to the second element, and so on. If only one ID or sObject is passed in, the LockResult array contains a single element.

## Example

The following example obtains and iterates through the returned Approval.LockResult objects. It locks some queried accounts using Approval.lock with a false second parameter to allow partial processing of records on failure. Next, it iterates through the results to determine whether the operation was successful for each record. It writes the ID of every record that was processed successfully to the debug log, or writes error messages and failed fields of the failed records.

// Query the accounts to lock
Account\[\] accts = \[SELECT Id from Account WHERE Name LIKE 'Acme%' WITH USER\_MODE\];
// Lock the accounts
Approval.LockResult\[\] lrList = Approval.lock(accts, false);

// Iterate through each returned result
for(Approval.LockResult lr : lrList) {
    if (lr.isSuccess()) {
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully locked account with ID: ' + lr.getId());
    }
    else {
        // Operation failed, so get all errors                
        for(Database.Error err : lr.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Account fields that affected this error: ' + err.getFields());
        }
    }
}

- **[LockResult Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Approval_LockResult.htm#apex_Approval_LockResult_methods)**

#### See Also

- [Approval Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_approval.htm#apex_methods_system_approval "Contains methods for processing approval requests and setting approval-process locks and unlocks on records.")

## LockResult Methods

The following are methods for LockResult.

- **[getErrors()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Approval_LockResult.htm#apex_Approval_LockResult_getErrors)**  
    If an error occurred, returns an array of one or more database error objects, providing the error code and description.
- **[getId()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Approval_LockResult.htm#apex_Approval_LockResult_getId)**  
    Returns the ID of the sObject you are trying to lock.
- **[isSuccess()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Approval_LockResult.htm#apex_Approval_LockResult_isSuccess)**  
    A Boolean value that is set to true if the lock operation is successful for this object, or false otherwise.

### getErrors()

If an error occurred, returns an array of one or more database error objects, providing the error code and description.

#### Signature

public List<Database.Error> getErrors()

#### Return Value

Type: [List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm#apex_methods_system_list "Contains methods for the List collection type.")<[Database.Error](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database_error.htm#apex_Database_Error_methods)\>

### getId()

Returns the ID of the sObject you are trying to lock.

#### Signature

public Id getId()

#### Return Value

Type: [Id](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_id.htm#apex_methods_system_id "Contains methods for the ID primitive data type.")

#### Usage

If the field contains a value, the object was locked. If the field is empty, the operation was not successful.

### isSuccess()

A Boolean value that is set to true if the lock operation is successful for this object, or false otherwise.

#### Signature

public Boolean isSuccess()

#### Return Value

Type: [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm#apex_methods_system_boolean "Contains methods for the Boolean primitive data type.")