Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the user-registration
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php on line 6121
Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hashone
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php on line 6121
Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896
{"id":585,"date":"2017-03-10T22:49:26","date_gmt":"2017-03-10T22:49:26","guid":{"rendered":"http:\/\/ccloudonline.nl\/a-homepage-section\/?p=585"},"modified":"2017-04-16T20:48:47","modified_gmt":"2017-04-16T20:48:47","slug":"you-got-to-love-them-maps","status":"publish","type":"post","link":"http:\/\/ccloudonline.nl\/?p=585","title":{"rendered":"You got to love them, Maps .."},"content":{"rendered":"
In this example I want to use a technique that will help us to avoid inserting for loops inside other for loops. Let’s say you want to compare a couple of fields from different objects, in many situations you will find something similar to this: <\/p>\n
[code lang=”php”]
\n\/\/SOQL queries to retrieve our values<\/p>\n
List<Lead> leadList = [SELECT Id, Email FROM Lead WHERE Email!= null];
\nList<Contact> contactList = [SELECT Id, Email FROM Contact WHERE Email != null]; <\/p>\n
for(Lead l: leadList)
\n{
\n for(Contact c: contactList)
\n {
\n if(l.Email == c.Email)
\n {
\n system.debug(‘There are emails matching: ‘
\n + ‘Contact Email:’ + c.Email
\n + ‘ with Lead Email: ‘ + l.email);
\n }
\n }
\n}<\/p>\n
[\/code]<\/p>\n
If you run this code in an anonymous window it will run fine. The problem is that running for loops within for loops can easily reach the governor limits for the number of executed code statements which today is 200000. <\/p>\n
In these situations is where we can use Map collections to help us reduce the possibility of reaching those nasty but important governor limits. <\/p>\n
[code lang=”php”]
\n\/\/SOQL queries to retrive our values<\/p>\n
List<Lead> leadList = [SELECT Id, Email FROM Lead WHERE Email!= null];
\nList<Contact> contactList = [SELECT Id, Email FROM Contact WHERE Email != null]; <\/p>\n
\/\/This map will contain one of the objects and we will be using later to compare.
\n\/\/Either Object can be used for this reference map. <\/p>\n
Map<String, Lead> leadMap = new Map<String, Lead>();<\/p>\n
for (Lead le : leadList)
\n {
\n leadMap.put(le.Email, le);
\n } <\/p>\n
\/\/After passing key and value to our map(le.Email, le) we can use a for loop
\n\/\/to compare both records. <\/p>\n
for (Contact co: contactList)
\n {
\n if (leadMap.containsKey(co.Email))
\n {
\n system.debug(‘We found an equal email on a Lead for this Contact: ‘ + co.Email);
\n } <\/p>\n
} <\/p>\n
[\/code]<\/p>\n
This technique can save us of trouble and it is a good way to use Maps just to stay away from governor limits.<\/p>\n","protected":false},"excerpt":{"rendered":"
Maps vs For loops, Round 1 In this example I want to use a technique that will help us to avoid inserting for loops inside other for loops. Let’s say you want to compare a couple of fields from different objects, in many situations you will find something similar to this: [code lang=”php”] \/\/SOQL queries […]<\/p>\n","protected":false},"author":1,"featured_media":640,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-585","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apex"],"_links":{"self":[{"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/posts\/585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=585"}],"version-history":[{"count":11,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions"}],"predecessor-version":[{"id":852,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions\/852"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/media\/640"}],"wp:attachment":[{"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}