Wednesday , December 13 2017

DML Operation

DML Operation contd

Upserting records

This command incorporates two DML operation i.e. insert and update in one statement. It has to be provided with a unique identifier such as Record Id, so that it can search the database and find the requested record, if there is no record matching the record Id then a new record is created, if a match found then the record is updated. But if the record Id or key passed have multiple matches, then it neither updates nor creates a record and throw an error


Upsert Image


Upsert operation is supported in Dataloader, Apex, and API. It is feasible to create parent child relationship in one statement.


Below is the schematic representation of an Upsert Statement.



Upsert Schematic

Benefits of using Upsert:


It simplifies the process of insertion and updating the records, information about Salesforce Id is not mandatory we can use external Id for this purpose. We do not have to manually export and match the records.  It helps in preventing the duplication of records.


Best Practice for Upsert:


Make external Id, Unique and case insensitive. Make use of compound fields to make a unique identifiers.


Use Case for Upsert:

Export data from production to sandbox.

  1. Create a new field and make it as external Id, follow the best practice to make this field
  2. Deploy new field in the sandbox
  3. Start export of data from production and import to sandbox using the various tools available like dataloader or data import wizard
  4. Use the newly created field for matching the data in sandbox.


Upsert command and external id are very handy when we are integrating data from external datasource, with the help of external id we can reference our record. Most of the data uploading tool like dataloader, dataimport wizard or 3rd party connectore like boomi has options to specify the external Id.


Merge Records


If there are duplicates in your org then Merge operation comes into picture to help you clean up the data.


Merge operation can take up to three records , update the selected record and delete the other two records, in case the delete records have related objects then these objects get reparented.


Merge is mainly available on Contacts, lead and account object


Steps to merge these standard objects are mentioned below:


  1. Merge Duplicate Contacts
  2. Merge Duplicate Accounts
  3. Merge Duplicate Leads



About Sumit Datta

Sumit Datta

I am a 3x Certified Salesforce developer with overall 4.5 years of IT experience and 2.5 years of Implementation experience in Salesforce. I am here to share my knowledge and help Beginners in Salesforce to understand the concepts of Apex, Visualforce and Salesforce Configuration.

Check Also


Dreamforce Global Gathering 2017, my experience and why one should not miss this event.

Dreamforce Global Gathering 2017, my experience and why one should not miss this event. First …

Salesforce AppBuilder Certification

Salesforce AppBuilder Certification Mock Exam 1

Want to test your preparation for the Salesforce AppBuilder Certification?   Salesforce AppBuilder Certification mock Exam …

Salesforce Platform Developer 1 Certification

Salesforce Platform Developer 1 Certification Mock Exam 2

Want to test your preparation for the Salesforce Platform Developer 1 Certification? Then go through …

Advanced Formula, Salesforce Platform unleashed!!!

Advanced Formulas Introduction to formula fields and Advanced Formulas Formula Field is a powerful capability …

Leave a Reply

Your email address will not be published. Required fields are marked *