Free Salesforce Developers Tutorials >

Chapter 8 - Apex DML and Database Methods >

Upsert | APEX DML Standalone Statements

Upsert | APEX DML Standalone Statements

What You’ll Learn

S2 Labs

Upsert In Salesforce

To create or update the existing data, you need to use an upsert statement.


List < Contact > newConList = new List < Contact > ();
List < Contact > conList = [SELECT firstname, lastname FROM contact];
Integer i = 1;
for (Contact cc: conList) {
    String s =;
    if (s.conatins(‘Contact’)) { = ‘1234’;
    } else {
        Contact c1 = new Contact(lastname = ’Contact’ + i);
upsert newconList;


Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

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