• Mradula Jain 5
  • NEWBIE
  • 28 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Its a well known fact that loops inside of loops, especially nested more than once, can be catastrophic for CPU performance. 
for(Integer a = 1; a <= 100; a++) {
    for(Integer b = 1; b <= 100; b++) {
        for(Integer c = 1; c <= 100; c++) {
            System.debug(a * b * c);
        }
    }
}
Is there any alternative algorithm to avoid  nested loops?
I want to know the best practices to avoid the nested loop scenarios if possible.
Thanks !!

 
Its a well known fact that loops inside of loops, especially nested more than once, can be catastrophic for CPU performance. 
for(Integer a = 1; a <= 100; a++) {
    for(Integer b = 1; b <= 100; b++) {
        for(Integer c = 1; c <= 100; c++) {
            System.debug(a * b * c);
        }
    }
}
Is there any alternative algorithm to avoid  nested loops?
I want to know the best practices to avoid the nested loop scenarios if possible.
Thanks !!

 
Hai,
 Batch apex code for account filedupdate: Getting below error,can anybody help me?
[Error] Error: Compile Error: Argument type of global method must also be global: List<Account> at line 9 column 17

CODE:
global class Accountupdate implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT Id,Name,Phone FROM Account ';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        for (Account a : scope)
        {
           a.Phone='123';
        }
        update a;
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}