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 foreach loop where its even elements are iterated. (infinite loop)

Our Recent Blog

Share This Post