• hwelch15
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

If I return 200 records an put them in a list.

 

If i update 50 of them, what is the best way to perform the update:

 

1. Update the List (which triggers the update context triggers for all 200 records

    

     For(Account[] al : [Select ID, BillingPostalCode From Account Limit 200]){

           For(Account a : al){           

                      if (a.Name.contains('50')){ //Returns only 50 of the 200 records

                             a.BillingPostalCode = 54321;

           }

     update al;

     }

 

2. or keep track of the updated records and only update those 50 (at a cost to heap size)

 

Account[] tbuAcc = New Account[]{};

 

For(Account[] al : [Select ID, BillingPostalCode From Account Limit 200]){

           For(Account a : al){           

                      if (a.Name.contains('50')){ //Returns only 50 of the 200 records

                             a.BillingPostalCode = 54321;

                             tbuAcc.add(a);

           }

     if(tbuAcc.size() >0)

         update tbuAcc;

     }