2

I am using url rewriter to convert all salesforce urls in a page to friendly url. the generate url method invokes many times(number of urls in the page) Is this how this method invoked, I thought it will invoke only time. And getting too many soql queries 101 exception. I have tried every possible solutions. But was not able to overcome this issue. Please help me. The issue occurred in this line.

for ( Tour_Records__c tourRecord : [SELECT Tour_Code__c FROM Tour_Records__c WHERE Id IN: tourRecords])

global PageReference[] generateUrlFor(PageReference[] SalesforceUrls){
   system.debug(SalesforceUrls.size());
    List<Id> tourRecords = new List<Id>();
    List<PageReference> FriendlyUrls = new List<PageReference>();
    Set<String> urlsReceived = new Set<String>();
    for(PageReference salesforceUrl : SalesforceUrls){
        String url = salesforceUrl.getUrl();
        if(url.startsWith(TOUR_VISUALFORCE_PAGE)){
            system.debug(url+'<<TOUR_VISUALFORCE_PAGE<<'+TOUR_VISUALFORCE_PAGE);
            if ( salesforceUrl.getParameters().get('id') != null ) {
                tourRecords.add( salesforceUrl.getParameters().get('id') );
            }
        }
    }

    List <Tour_Records__c> tourRecordList; 
   if (tourRecords.size() > 0 && SalesforceUrls.size() > 0 && SalesforceUrls.get(0).getUrl().startsWith(TOUR_VISUALFORCE_PAGE) && SalesforceUrls.get(0).getUrl().contains('id=') && !urlsReceived.contains(SalesforceUrls.get(0).getUrl())){
        tourRecordList = new List <Tour_Records__c>();
        for ( Tour_Records__c tourRecord : [SELECT Tour_Code__c FROM Tour_Records__c WHERE Id IN: tourRecords]) {
            tourRecordList.add ( tourRecord ); 
        }
        urlsReceived.add(SalesforceUrls.get(0).getUrl());
    }

    Integer counter = 0;
    for(PageReference salesforceUrl : SalesforceUrls) {

    //Get the URL of the page
        String url = salesforceUrl.getUrl();

        if(url.startsWith(TOUR_VISUALFORCE_PAGE)){
        system.debug('aaaaa');
            String bblPageURL='';
            if(!salesforceUrl.getParameters().isEmpty()){
                if(salesforceUrl.getParameters().get('id') != null && String.isNotBlank(salesforceUrl.getParameters().get('id'))){

                    String categoryType = salesforceUrl.getParameters().get('id');

                   if(tourRecordList.size()>0){
                        bblPageURL = '/Tour/'+tourRecordList.get(counter).Tour_Code__c;
                        counter++;
                        FriendlyUrls.add(new PageReference(bblPageURL));
                    }
                    system.debug(FriendlyUrls+'77777');
                }
            }

        }

    }
    system.debug(FriendlyUrls+'999');
    return FriendlyUrls;
}

Here is the link used in page

<apex:repeat value="{!allTourRecords}" var="tour" >
                        <div class="tour_row">
                                <h2>{!tour.Name}</h2>
                                <div class="bar_separator"></div>

                                <div class="tour_type_parent">
                                <apex:repeat value="{!tour.Country_Tours__r}" var="country">
                                    <div class="tour_type">
                                        <div class="tour_img">
                                            <img src="{!iconImage[country.Tour__c]}" />
                                        </div>
                                        <div class="tour_detail">
                                            <h3>
                                                <a href="{!URLFOR($Page.CJ_Tour,null,[id=country.Tour__c])}">{!country.Tour__r.Name}</a>
                                            </h3>
                                            <p>{!country.Tour_Type__c}</p>
                                            <div class="tour_duration"><span>{!country.Tour__r.Days__c} Days,</span><span>{!country.Tour__r.Nights__c} Nights</span></div>
                                            <div class="tour_months"><span>{!country.Tour__r.Tour_Months_String__c}</span></div>
                                            <div class="learn_more">
                                                <a href="{!URLFOR($Page.CJ_Tour,null,[id=country.Tour__c])}">LEARN MORE</a>
                                            </div>
                                        </div>
                                    </div>
                                    </apex:repeat>
                            </div>

                        </div>
                    </apex:repeat>

Please find the debug log below.

[1]|01pW00000002EQz|CJUrlRewriter.CJUrlRewriter() 03:52:43.143 (143992666)|METHOD_EXIT|[1]|CJUrlRewriter 03:52:43.150 (150715701)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.155 (155402627)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.180 (180242988)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.184 (184089809)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.207 (207945090)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.211 (211892907)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.235 (235226470)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.238 (238721963)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.261 (261936813)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.265 (265375589)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.290 (290098103)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.293 (293608133)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.318 (318970898)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.323 (323843067)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.347 (347171313)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.351 (351730950)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.375 (375424676)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.379 (379009125)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.402 (402494031)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.406 (406344425)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.430 (430917613)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.434 (434670318)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.457 (457844736)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.461 (461429522)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.484 (484518639)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.488 (488145811)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.511 (511657464)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.515 (515821564)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.539 (539149554)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.542 (542723837)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.574 (574845576)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.579 (579124404)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.605 (605319655)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.609 (609350099)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.632 (632787353)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.636 (636756385)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.660 (660106850)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.665 (665661826)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.688 (688834125)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.692 (692418051)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.715 (715724848)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.721 (721568482)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.745 (745107079)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.748 (748961224)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.772 (772294805)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.775 (775999481)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.799 (799498091)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.803 (803339079)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.826 (826727204)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.830 (830432545)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.853 (853775279)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.857 (857309558)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.880 (880926215)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.884 (884840903)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.908 (908174539)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.912 (912105423)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.935 (935432294)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.939 (939075681)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.969 (969868696)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:43.974 (974850383)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:43.998 (998162315)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.002 (1002492953)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.025 (1025834131)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.030 (1030644952)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.055 (1055480564)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.059 (1059255461)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.082 (1082801999)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.086 (1086253323)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.109 (1109564569)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.113 (1113084843)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.136 (1136461883)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.140 (1140131047)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.163 (1163390298)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.166 (1166980688)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.191 (1191678697)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.195 (1195493076)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.219 (1219083647)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.222 (1222784374)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.246 (1246083500)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.249 (1249498102)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.273 (1273465282)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.277 (1277393951)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.304 (1304389043)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.308 (1308080241)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.331 (1331768345)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.335 (1335328689)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.358 (1358786104)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.362 (1362376669)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.386 (1386083581)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.389 (1389860572)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.413 (1413099576)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.416 (1416924109)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.440 (1440291413)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.444 (1444099214)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.467 (1467394752)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.470 (1470939829)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.494 (1494188180)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.497 (1497816676)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.521 (1521633778)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.525 (1525272025)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.548 (1548634156)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.552 (1552144516)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.575 (1575891000)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.579 (1579559135)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.603 (1603225233)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.607 (1607131495)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.631 (1631259612)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.635 (1635167683)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.658 (1658482972)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.662 (1662777758)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.686 (1686179966)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.689 (1689762791)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.713 (1713178798)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.716 (1716730973)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.740 (1740035194)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.743 (1743610694)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.767 (1767631386)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.771 (1771772287)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.796 (1796316342)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.800 (1800493353)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.824 (1824608237)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.829 (1829883148)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.853 (1853360774)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.856 (1856983637)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.880 (1880741717)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.884 (1884285528)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.908 (1908081172)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.912 (1912002263)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.944 (1944317918)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.948 (1948550316)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.972 (1972688672)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:44.976 (1976225754)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:44.999 (1999786673)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.003 (2003351011)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.026 (2026596963)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.030 (2030104714)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.053 (2053804072)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.057 (2057417487)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.083 (2083628984)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.087 (2087812129)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.117 (2117828851)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.121 (2121958230)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.146 (2146635686)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.150 (2150164685)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.173 (2173439860)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.176 (2176991248)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.200 (2200384739)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.204 (2204123515)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.229 (2229447744)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.233 (2233030786)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.256 (2256672251)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.260 (2260332571)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.288 (2288095729)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.291 (2291806613)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.315 (2315605943)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.319 (2319327551)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.343 (2343157861)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.346 (2346679951)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.370 (2370174896)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.375 (2375338418)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.406 (2406079250)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.410 (2410409347)|SOQL_EXECUTE_END|[72]|Rows:17 03:52:45.436 (2436069894)|SOQL_EXECUTE_BEGIN|[72]|Aggregations:0|SELECT Tour_Code__c FROM Tour_Records__c 03:52:45.440 (2440250078)|SOQL_EXECUTE_END|[72]|Rows:17 *** Skipped 11796884 bytes of detailed log

Updated Visualforce page and apex class.

<div class="tour_list">
                   <apex:repeat value="{!allPages}" var="country">
                        <a href="{!URLFOR($Page.CJ_Tour,null,[id=country])}">Learn More</a>
                   </apex:repeat>
                </div>

ApexClass

allTourRecords = [SELECT Id,Name,(SELECT Id, Tour__c, Tour__r.Name,Tour__r.Days__c,Tour__r.Nights__c, Tour__r.Tour_Months_String__c,
                                            Tour__r.Tour_Picture_URL__c,Tour__r.Tour_HeaderUrl__c, Tour__r.Tour_Code__c,
                                            Tour_Type__c FROM Country_Tours__r ORDER BY Tour__r.Name) 
                            FROM Country__c WHERE Display_on_Itineraries__c = true ORDER BY Name];
       allPages = new List<String>();
       for(Country__c country : allTourRecords){
           for(Country_Tours__c tour : country.Country_Tours__r){
               allPages.add(tour.Tour__c);
           }
       }
6
  • Hi, I don't think the too many SOQL queries is occuring because of this method. How are you invoking generateUrlFor method ? You might be invoking the method too many times which causes the limit to be hit. Remember every invocation of this method can use one SOQL query. Hope this helps you debug the issue.
    – Learner
    Commented Aug 9, 2015 at 7:57
  • I have invoked a urlfor statement in apex repeat in visualforce page. Is that the problem ? If it is the problem, how can I modify it without affecting the current functionality ? Commented Aug 9, 2015 at 8:05
  • I doubt you are invoking the method directly from VF page since it accepts parameters. Could you elaborate what you are doing/calling in URLFOR in apex:repeat.
    – Learner
    Commented Aug 9, 2015 at 8:17
  • I have added that apex repeat to the question. Please check it. Commented Aug 9, 2015 at 8:35
  • 1
    You have a soql statement in a repeat. If you have more than 100 rows (assuming no other queries on the controller) you will hit the governor limit. You should really are your query outside the repeat/method call. It will be a less selective query but will ensure you don't hit limits. You could also limit the rows queried for in the repeat as well (tour.country_tours__r) Commented Aug 9, 2015 at 17:27

2 Answers 2

1

It simple,

you have {!URLFOR($Page.CJ_Tour,null,[id=country.Tour__c])}" in an apex repeat thus being executed many time.

You really should be doing this logic in the class then then using the page to display the collection

Change generateUrlFor to populate a String [] and use that in the page.....

Without the rest of your class and page it is hard to say how best to rewrite it.

Interesting though as I have never seen the URLFOR used like that to call a control method....Learn something everyday

3
  • I have modified it based on your comment, but still getting the same issue. Please find the controller code and new edits added to the code Commented Aug 10, 2015 at 6:10
  • you still have <a href="{!URLFOR($Page.CJ_Tour,null,[id=country])}"> in your repeat. This is the part you need to change to a collection. Because each time that tag is rendered it call the method and then execute the query....Again, it executes the entire method on each iteration of the repeat.
    – Eric
    Commented Aug 10, 2015 at 6:26
  • Could you please provide an example on how to achieve this? Commented Aug 10, 2015 at 7:01
0

Thanks for all your replies.

Finally I found out what the issue was. This error was occurring because if you have not handled a url in urlfor in UrlRewriter

For example, consider this case I have a url redirect in my page and there is no conditions or code is added in the URL rewriter to handle this page. So it will check the whole loop again and again to find a match to this page. That's why I am getting "too many soql exception" {!URLFOR($Page.CJ_TourClone,null,[id=country.Tour__c])}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .