function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sachin shah 27sachin shah 27 

Hi All,Difference between update and upsert?

Best Answer chosen by sachin shah 27
PrasathPrasath
Update Statement
The update DML operation modifies one or more existing sObject records, such as individual accounts or contactsinvoice statements, in your organization’s data. update is analogous to the UPDATE statement in SQL.
Syntax
update sObject
Upsert Statement
The upsert DML operation creates new records and updates sObject records within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
Syntax
upsert sObject​​


 

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Sachin,

Please find the difference between upsert and update below.

Insert: Whenever you perform update DML operation it will directly update the existing records in the database.If same record is already existing in the database it will replace the existing record.

Upsert: Whenever you perform upsert DML operation it will first check if the record is already existing in the database or not if it's existing then it will update the record.If the record is not existing in the database then it will insert a new record in the database.

Please mark this as solved if the information helps so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Regards,
Nagendra.

 
 
PrasathPrasath
Update Statement
The update DML operation modifies one or more existing sObject records, such as individual accounts or contactsinvoice statements, in your organization’s data. update is analogous to the UPDATE statement in SQL.
Syntax
update sObject
Upsert Statement
The upsert DML operation creates new records and updates sObject records within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
Syntax
upsert sObject​​


 
This was selected as the best answer
sachin shah 27sachin shah 27
Thank you @Prasath P