UpsertResult Class

The result of an upsert DML operation returned by the Database.upsert method.

Database

An array of Database.UpsertResult objects is returned with the upsert database method. Each element in the UpsertResult array corresponds to the sObject array passed as the sObject[] parameter in the upsert Database method; that is, the first element in the UpsertResult array matches the first element passed in the sObject array, the second element corresponds with the second element, and so on. If only one sObject is passed in, the UpsertResults array contains a single element.

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

  • getErrors()

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

  • getId()

    Returns the ID of the sObject you were trying to update or insert.

  • isCreated()

    A Boolean value that is set to true if the record was created, false if the record was updated.

  • isSuccess()

    Returns a Boolean value that is set to true if the DML operation was successful for this object, false otherwise.

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

public Database.Error[] getErrors()

Type: Database.Error []

Returns the ID of the sObject you were trying to update or insert.

public ID getId()

Type: ID

In API version 53.0 and later, the method returns the sObject ID. However, if record locking fails during the update operation, the method returns a null value.

In API version 52.0 and earlier, the method returned a null value if the record wasn’t updated successfully.

A Boolean value that is set to true if the record was created, false if the record was updated.

public Boolean isCreated()

Type: Boolean

Returns a Boolean value that is set to true if the DML operation was successful for this object, false otherwise.

public Boolean isSuccess()

Type: Boolean