I was trying to implement the urlrewriter as mentioned in the below url
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_site_urlRewriter.htm
want to know how this generateURLfor method will be invoked?
I have a mentioned a List<PageReference> as a parameter to this, I dont see this function called anywhere in debug logs for any of my sites user or site guest user.
Not sure how this piece is invoked and am getting a too many script statements error. Not sure why?
But if I remove this URLRewriter part, am not getting that error.
Can someone help here please ? I have posted my code below.
String FRIENDLY_GROUPS_PAGE = '/groups/';
Map<Id, Group__c> mapgroups;
String GROUPDETAILS_VISUALFORCE_PAGE = '/GroupDetails?groupid=';
global List<PageReference> generateUrlFor(List<PageReference> mySalesforceUrls)
{
system.debug('inside generateurlfor');
//A list of pages to return after all the links
//have been evaluated
if (mySalesforceUrls.size() > 0 && mySalesforceUrls.get(0).getUrl().startsWith(GROUPDETAILS_VISUALFORCE_PAGE) && !mySalesforceUrls.get(0).getUrl().contains('&'))
{
List<PageReference> myFriendlyUrls = new List<PageReference>();
//a list of all the ids in the urls
List<id> grpIds = new List<id>();
// loop through all the urls once, finding all the valid ids
for(PageReference mySalesforceUrl : mySalesforceUrls)
{
//Get the URL of the page
String url = mySalesforceUrl.getUrl();
if(url.startsWith(GROUPDETAILS_VISUALFORCE_PAGE) && !url.contains('&'))
{
//Extract the ID from the query parameter
//and store in a list
//for querying later in bulk.
string id= url.substring(GROUPDETAILS_VISUALFORCE_PAGE.length(),url.length());
grpIds.add(id);
}
}
// Get all the group names in bulk
List<Group__c> groups = [SELECT Name FROM Group__c WHERE Id IN :grpIds];
// make the new urls
Integer counter = 0;
// it is important to go through all the urls again, so that the order
// of the urls in the list is maintained.
if (mySalesforceUrls != null)
{
system.debug(LOGGINGLEVEL.WARN,'count of mySalesforceUrls : ' + mySalesforceUrls.size());
}
for(PageReference mySalesforceUrl : mySalesforceUrls)
{
//Get the URL of the page
String url = mySalesforceUrl.getUrl();
if(url.startsWith(GROUPDETAILS_VISUALFORCE_PAGE) && !url.contains('&') )
{
myFriendlyUrls.add(new PageReference(FRIENDLY_GROUPS_PAGE + groups.get(counter).name));
counter++;
}
else
{
//If this doesn't start like a groups page,
//don't do any transformations
myFriendlyUrls.add(mySalesforceUrl);
}
}
//Return the full list of pages
return myFriendlyUrls;
}
else
{
return mySalesforceUrls;
}
}
** edited and added the following ******* now the issue is even worser.. I have commented out everything inside these methods and just said return null. despite doing that its throwing too many script statements error..
But strange thing is that, if I remove this URLRewriter class configuration from my sites config, its not throwing any error and its working fine :(