You need to sign in to do that
Don't have an account?

Url rewriting not taking other fields except page name for output url in cmsforce
Hi all,
I have written the url rewriter class to construct friendly urls for cmsforce. But i am not able to use some other field except page name to get the final url. I have used a text field url name in page object to get the final url.
Please see my code below and let me know if i am missing something !
global class myurlrewriter implements Site.UrlRewriter {
//Variables to represent the friendly URLs for pages assuming 3 account managers
String DIRECTORY = '/internal/';
//Variables to represent my custom Visualforce pages that display page information
String VISUALFORCE_PAGE = '/page?pageid=';
// The first global method for mapping external URL to an internal one
global PageReference mapRequestUrl(PageReference myFriendlyUrl){
String url = myFriendlyUrl.getUrl();
if(url.startsWith(DIRECTORY)){
String name = url.substring(DIRECTORY.length(),url.length());
//Select the ID of the page that matches the name from the URL
Page__c site_page = [select id,PageTemplate__r.id from Page__c where name =:name LIMIT 1];
//Construct a new page reference in the form of my Visualforce page
return new PageReference(VISUALFORCE_PAGE + site_page.id+'&tempid='+site_page.PageTemplate__r.id);
}
//If the URL isn't in the form of a cmsforce page, continue with the request
return null;
}
// The second global method for mapping internal Ids to URLs
global List<PageReference> generateUrlFor(List<PageReference> mySalesforceUrls){
//A list of pages to return after all the links have been evaluated
List<PageReference> myFriendlyUrls = new
List<PageReference>();
for(PageReference mySalesforceUrl : mySalesforceUrls){
//Get the URL of the page
String url = mySalesforceUrl.getUrl();
//If this looks like a page that needs to be mapped, transform it
if(url.startsWith(VISUALFORCE_PAGE)){
//Extract the ID from the query parameter
String id= url.substring(VISUALFORCE_PAGE.length(), url.length());
//Query for the name of the cmsforce page to put in the URL
Page__c site_page2 = [select url_name__c from Page__c where id =:id LIMIT 1];
//Construct the new URL
myFriendlyUrls.add(new PageReference(DIRECTORY+ site_page2.url_name__c));
}
else {
//If this doesn't start like an cmsforce page, don't do any transformations
myFriendlyUrls.add(mySalesforceUrl);
}
}
//Return the full list of pages
return myFriendlyUrls;
}
}
issue resolved
this line made it work
All Answers
issue resolved
this line made it work
Hi Gautam,
Do we have to create custom object as page__c and we have to store the url name, pagetemplates etc.,
I want to know on thing pageTemplate is an custom objects?
Please let me know. Thanks in advance