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)