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

Update statement in apex

The DML update statement is used to modify existing records in the salesforce database.

A common update requirement is modifying a customer's address in the system.

To update records in salesforce :

  • Find the record id of the exsiting record.
  • Once you have the Id of the record, create an instance of the corresponding object with the desired field updates
  • Use the DML update operation to save the changes.

Following is an example of a DML update statement in apex to modify an existing account record in salesforce.

Update Operation

Updates an existing record in the database.

Loading...

In the above example:

  • The variable accRecord gets its value from the database using an SOQL query, including the record id field.
  • The account's industry field is populated with value "Technology".
  • Finally, the DML Update statement is used to save the account changes to the database.

Try It Yourself

Loading...