In Apex, the update statement is used for performing data modification operations, specifically for updating existing
records in the Salesforce database. You can use the update statement to modify one or more fields of an existing record.
Here's a basic example of how to use the update statement to update an existing Account record:
// Query an existing Custom Object record to update
Custom_Object__c existingRecord = [SELECT Id, Name__c, Description__c FROM Custom_Object__c WHERE Name__c = 'Old Name' LIMIT 1];
// Modify the fields of the existing record
existingRecord.Name__c = 'Updated Name';
existingRecord.Description__c = 'Updated Description';
// Use the update statement to save the changes to the record
update existingRecord;
We first query an existing record of the custom object "Custom_Object__c" based on a specified condition using SOQL.
We retrieve the existing record into the existingRecord variable.
We modify the "Name__c" and "Description__c" fields of the existingRecord object to update the record.
We use the update statement to save the changes to the Salesforce database.