SFDC Map Method

 
http://www.sundoginteractive.com/sunblog/posts/apex-why-maps-are-your-friend

integer myCount = 0;
list<customa__c> myCustomA = new list<customa__c>();
myCustomA = [Select ID, myA__c, myAText__c From CustomA__c Where myA__c = false];

list<customb__c> myCustomB = new list<customb__c>();
myCustomB = [Select ID, myB__c, myBText__c From CustomB__c Where myB__c = false];

//Now create a map for B that we can do look-ups on.
map<string, customb__c=""> myBMap = new map<id, customb__c="">();
for (CustomB__c b : myCustomB){
   myBMap.put(b.myBText__c, b);
}

//Now do our matching loop, but use the map instead
for (CustomA__c a: myCustomA){
  if (myBMap.containsKey(a.myAText__c){
      myCount += 1;
  }
}

 

 

Print Friendly, PDF & Email
This entry was posted in Development and tagged , , , . Bookmark the permalink.