Notes
In Apex, the update
statement is used to modify existing records in the database. It is commonly employed in Salesforce development to update the fields of Salesforce objects such as Custom Objects, Standard Objects, etc.
Here's a brief explanation along with an example:
Account existingAccount = [SELECT Id, Name, Industry FROM Account WHERE Name = 'Example Account' LIMIT 1];
if (existingAccount != null) {
existingAccount.Name = 'Updated Account';
existingAccount.Industry = 'Finance';
update existingAccount;
if (existingAccount.Id != null) {
System.debug('Account updated successfully. Updated Account ID: ' + existingAccount.Id);
} else {
System.debug('Failed to update the Account.');
}
} else {
System.debug('Account not found for update.');
}
Output:
Account updated successfully. Updated Account ID: 001Dn00000oQLjkIAG
Video
Video does not exists.