You are on page 1of 5

=====================================================================================

===========

Salesforce Training By Mohan - VLR Training Institute ||| Contact: +91-6301332114

=====================================================================================
===========

Topic - For loop:

=========================================================================

* Used to iterate the list data

Syntax-1)

==================================================

for(integer i=0;i++;i<10){

==================================================

Ex-1)

=================================================

for(integer i=0;i<10;i++){

system.debug('i==>' + i);

=================================================

* SOQL(salesforce object query language)

- Retrieves the data[Records of all salesforce object] from database to apex


- sample syntax:

> select FieldAPIName from sObject

> select id,name from account

> select id from student__c

Syntax-2)

==================================================

for(sobjectAPIName variable : listOfSobjectVariableName){

for(Primitivedatatype variable:listvariablename){

list<account> alist = [select id from account];

for(account a:alist){

====================================================

Ex-1)

======================================================

list<account> alist = [select id,name from account];

for(account a:alist){
system.debug('a =>' + a);

======================================================

Syntax-3) Ex-1)

==================================================

for(acount a:[select id from account]){

system.debug('a =>' + a);

==================================================

Req-1) Update all account records based on the below conditions

if accontsource = web => Industry = media

if accontsource = phone enquery => Industry = Consulting

===============================================================

public class Nov4_ForLoopOne {

public list<account> accList;

public void iteration(){

accList = [select id,name,industry,AccountSource,Phone from account];

for(account a: accList){

system.debug('a===>' + a);

if(a.AccountSource == 'web'){

a.Industry = 'media';

}else if(a.AccountSource == 'Phone Inquiry'){


a.Industry = 'Consulting';

if(a.Phone == ''){

a.Phone = '33378897';

update accList;

_____________________________________________

Nov4_ForLoopOne s = new Nov4_ForLoopOne();

s.iteration();

Req-2) second for loop

======================

public class Nov4_ForLoopOne {

public void iteration(){

for(integer i=0;i<50;i++){ // 05<50 i++ ==> i = 49+ 1

system.debug('i==>' + i);

_____________________________________________

Nov4_ForLoopOne s = new Nov4_ForLoopOne();


s.iteration();

=====================================================================================
===========

Salesforce Training By Mohan - VLR Training Institute ||| Contact: +91-6301332114

=====================================================================================
===========

You might also like