"Too many SOQL queries: 101" - Apex error occurred while executing Site URL Rewriter

The number of executions of your SOQL query would be directly proportional to the number of invocations of generateUrlFor() in one execution context.

I'd recommend having the map to be an instance variable that is initialized at load. Depending on how many records your IPFooObject Object has, you could just have a map that loads up the whole map at startup, rather than lazy loading, which makes sense if IPFooObject has a prohibitively high number of records.

Map <Id, IPFooObject> groups; //instance variable

 if (groups != null) //check that this is not already initialized
       groups = new Map<Id, IPFooObject>([SELECT Name FROM IPFooObject]);

Then just get from this map each time you need to use it in your various methods


First thing which popups in my mind is loop of a page which calls that code.

First thing I would do is to remove/comment/whatever lines with SOQL to be sure that the problem is not in SOQL. I think the problem is in looping request to the page.


My aim is to handle the friendly urls. But I had been getting error while clicking on the export link. After trying different solutions, landed at this point.

Since the url invoked through this action is has no need to be validated as friendly url, I added extra if conditions in my URLRewrite class.

global PageReference mapRequestUrl(PageReference myFriendlyUrl)
{
    String url = myFriendlyUrl.getUrl();        
    if(url.startsWith(FOO_PAGE) && isNumber(url.substring(FOO_PAGE.length(),url.length())) && !url.contains('&'))
    {
        ...
    }
}

global List<PageReference> generateUrlFor(List<PageReference> mySalesforceUrls)
{
    if (mySalesforceUrls.size() > 0 && mySalesforceUrls.get(0).getUrl().startsWith(FOO_VISUALFORCE_PAGE) && !mySalesforceUrls.get(0).getUrl().contains('&'))
    {
        ...
    }
}

This solved my problem. Instead of executing loop for all the pages, it will check only for the pages required. Thank you all for your suggestions.