Learn from industry experts! Admin batch starts from 19 Feb.
Hurry up!
Book your slot now!

8

Upsert | APEX DML Standalone Statements

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

Next Topic

Need more support?

Get a head start with our FREE study notes!

Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.

Book A 15-Minutes Free Career Counselling Today!