+ Start a Discussion
SandrineSandrine 

Does upsert works like update

Hello,

For a custom object i have around 100 custom fields.
I want to update some fields, i know that with Update my fucntion will work but i was wondering if the Upsert does the same work too.
I dont want to loose the earlier values.

Thank you for suggestions
Best Answer chosen by Sandrine
Dhanya NDhanya N
Hi Sandrine,

Using the upsert operation, you can either insert or update an existing record in one call. To determine whether a record already exists, the upsert statement or Database method uses the record’s ID as the key to match records, a custom external ID field, or a standard field with the idLookup attribute set to true.
If the key is not matched, then a new object record is created.
If the key is matched once, then the existing object record is updated.

Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_upsert.htm

Thanks,
Dhanya

All Answers

Dhanya NDhanya N
Hi Sandrine,

Using the upsert operation, you can either insert or update an existing record in one call. To determine whether a record already exists, the upsert statement or Database method uses the record’s ID as the key to match records, a custom external ID field, or a standard field with the idLookup attribute set to true.
If the key is not matched, then a new object record is created.
If the key is matched once, then the existing object record is updated.

Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_upsert.htm

Thanks,
Dhanya
This was selected as the best answer
Dhanya NDhanya N
Sandrine, let me know if it helps you.