Monday, January 6, 2014

Execute Anonymous - II

Execute Anonymous :
Continuous to previous post some more examples to understand debugging and governor limits using execute anonymous

List<Contact> contactList = new List<Contact>();
for(Integer i=0; i <= 5; i++){
  for(Integer j=0; j <= 10; j++){
    if(i < j) {
      System.debug('i is less than j');
      Integer k=i;
      while(k < j){
        System.debug('k < j');
        k++;
  }
     } else {
        System.debug('i is not less than j');
     }
  }
 }
-----------------------------------------------------------------------------------------------------
 public class ContactCounter{
  public void countSmithContacts(List<Contact> listOfContacts){
     // the code of the method goes here…
    Integer smithCounter = 0;
     for(Contact c : listOfContacts){
      if(c.lastname=='Smith'){
        smithCounter++;
         System.debug('Smith #' + smithCounter);
  }
     }
  }
 }
------------------------------------------------------------------------------------------------------
String stateAbbreviation = 'IL';
String stateName;
if (stateAbbreviation == 'IL') {
stateName = 'Illinois';
} else if (stateAbbreviation == 'IA') {
stateName = 'Iowa';
} else if (stateAbbreviation == 'CA') {
stateName = 'California';
}
System.debug('State = ' + stateName);


Here is the governor limits info for first example

No comments:

Post a Comment