ONE DAY SALE

Free Salesforce Developers Tutorials >

Chapter 8 - Apex DML and Database Methods >

Update | APEX DML Standalone Statements

Update | APEX DML Standalone Statements

What You’ll Learn


S2 Labs

Apex Update DML Statement 

To update an existing record, you need to use the update statement.

Example 1:

public static void main() {
    Account a = [SELECT Name from Account WHERE Name like‘ Sh % ’LIMIT 1]
    a.name = ‘Cyntexa’;
    update a;
}

Example 2:

 List < Contact > conList = [SELECT firstname, lastname FROM Contact WHERE
    createdDate = Today
];
Integer i = 1;
for (Contact cc: conList) {
    cc.firstname = cc.firstname + i);
i++;
}
update conList;

Note:

We cannot modify a list or collection in a for-each loop where its even elements are iterated. (infinite loop)

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 *