---
schema_version: "1"
id: 03529225994a2b537540d7fdda9cafb7702786e79db8d7ca6892fe03361a37bf
title: Error Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_methods_system_database_error.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database_error.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: d37da0565147c6a02ca2e6a1adfdba7e1d0b5245daf3546b5ea642520c754d92
description: Represents information about an error that occurred during a DML operation when using a Database method.Returns an array of one or more field names. Identifies which fields in the object, if any, affected the error condition.Returns the error message text.Returns a code that characterizes the error.
---
# Error Class

Represents information about an error that occurred during a DML operation when using a Database method.

## Namespace

[Database](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Database.htm "The Database namespace provides classes used with DML operations.")

## Usage

Error class is part of SaveResult, which is generated when a user attempts to save a Salesforce record.

#### See Also

- [SaveResult Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database_saveresult.htm#apex_methods_system_database_saveresult "The result of an insert or update DML operation returned by a Database method.")
- [DuplicateError Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_DuplicateError.htm#apex_class_Database_DuplicateError "Contains information about an error that occurred when an attempt was made to save a duplicate record. Use if your organization has set up duplicate rules, which are part of the Duplicate Management feature.")

## Error Methods

The following are methods for Error. All are instance methods.

- **[getFields()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database_error.htm#apex_Database_Error_getFields)**  
    Returns an array of one or more field names. Identifies which fields in the object, if any, affected the error condition.
- **[getMessage()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database_error.htm#apex_Database_Error_getMessage)**  
    Returns the error message text.
- **[getStatusCode()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database_error.htm#apex_Database_Error_getStatusCode)**  
    Returns a code that characterizes the error.

### getFields()

Returns an array of one or more field names. Identifies which fields in the object, if any, affected the error condition.

#### Signature

public String\[\] getFields()

#### Return Value

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

### getMessage()

Returns the error message text.

#### Signature

public String getMessage()

#### Return Value

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

### getStatusCode()

Returns a code that characterizes the error.

#### Signature

public StatusCode getStatusCode()

#### Return Value

Type: StatusCode

#### Usage

The full list of status codes is available in the WSDL file for your organization (see Downloading Salesforce WSDLs and Client Authentication Certificates in the Salesforce online help.)