This course is currently a work in progress. Please join the waitlist to receive regular updates.

Delete statement in apex

The DML delete statement is used to delete existing records from the salesforce database. To delete records, you need the Id's of the existing records.

Once you have the record instances with id of the record, use the DELETE operation to delete the records from the salesforce database.

Here is an example of a DML delete statement to delete an existing account record in salesforce.

Delete Operation

Delete a record from the database.

Loading...

In the above example:

  • The variable accRecord is used to query an existing record from the database. The SOQL query written with a limit statement, which returns a single record from the database.
  • The query result include the record id, and the DELETE statement is used to delete the record from the database.

Note


Once records are deleted from the database, Salesforce will, by default keep the deleted records in the Recycle Bin for 15 days before permanently deleting them from the database.

Try It Yourself

Loading...