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.

Example

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

salesforce-developer

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 *