Hi Ramesh, 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.
Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Upsert: 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.
Upserting Records: ----------------------- If you have a list containing a mix of new and existing records, you can process insertions and updates to all records in the list by using the upsert statement. Upsert helps avoid the creation of duplicate records and can save you time as you don’t have to determine which records exist first.
Upsert uses the sObject record's primary key (the ID), an idLookup field, or an external ID field to determine whether it should create a new record or update an existing one: If the key is not matched, a new object record is created. If the key is matched once, the existing object record is updated. If the key is matched multiple times, an error is generated and the object record is neither inserted or updated.
Q: If I have a comment field and some records have information populated in them and some don't, would using Upsert allow me to add additional information to comment field with data already in them or will it overwrite them?
I'm looking at updating several thousand records and need to add additional information for a period of time and then remove that info at a later date.
Hi, vid in my knowledge, data in your comment field get updated when you use upsert operation because it matched the salesforce id or either external id and if there is no data in your comment field it will get inserted same time.
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.
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_upsert.htm
- https://success.salesforce.com/answers?id=90630000000guxnAAA
hope it helps.Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Rahul Kumar
Upserting Records:
-----------------------
If you have a list containing a mix of new and existing records, you can process insertions and updates to all records in the list by using the upsert statement.
Upsert helps avoid the creation of duplicate records and can save you time as you don’t have to determine which records exist first.
Upsert uses the sObject record's primary key (the ID), an idLookup field, or an external ID field to determine
whether it should create a new record or update an existing one:
If the key is not matched, a new object record is created.
If the key is matched once, the existing object record is updated.
If the key is matched multiple times, an error is generated and the object record is neither inserted or updated.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_upsert.htm
Q: If I have a comment field and some records have information populated in them and some don't, would using Upsert allow me to add additional information to comment field with data already in them or will it overwrite them?
I'm looking at updating several thousand records and need to add additional information for a period of time and then remove that info at a later date.
in my knowledge, data in your comment field get updated when you use upsert operation because it matched the salesforce id or either external id and if there is no data in your comment field it will get inserted same time.
Thanks
Yash Shrivastava
https://lottery-sambad.xyz
عزل اسطح
شركة عزل اسطح
عزل الاسطح بجدة
شركة عزل بجدة