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

URL Rewriter and Test Class
A couple of questions here:
1) Does this URL Rewriter class look functional? I thought I read that I didn't necessarily need the second generateURL function, but I'm not sure.
global with sharing class myRewriter implements Site.UrlRewriter { String VIP_PAGE = '/VIP/'; String VIP_VISUALFORCE_PAGE = '/VIP?id='; global PageReference mapRequestUrl(PageReference myFriendlyUrl){ String url = myFriendlyUrl.getUrl(); if(url.startsWith(VIP_PAGE)){ String name = url.substring(VIP_PAGE.length(), url.length()); Lead ld = [select id from Lead where XUniqueSearchId__c =: name LIMIT 1]; return new PageReference(VIP_VISUALFORCE_PAGE + ld.id); } return null; } global List<PageReference> generateUrlFor(List<PageReference> mySalesforceUrls){ return null; } }
2) What should the test class for this consist of?
Thank you in advance for any assistance you may be able to provide!
Yes, your class looks functional.
Here is what your example looks like with some tests:
All Answers
Yes, your class looks functional.
Here is what your example looks like with some tests:
Also, unless you are using the UrlFor function in your pages and you want to change those URLs, you don't need to use the generateUrlFor method.
Thank you for your quick help with this.
I've run some tests and everything appears to be checking out, but when I try to use the friendlier URL I get a "Page Not Found" message. I've added the Rewriter class to the site settings and also to the enabled apex classes, so I'm not sure what's happening.
Am I missing something here?!
Is the VIP page added to your site as well?
I figured it out . . . doh!
VIP was the site, so really the link would have to be /VIP/VIP?id= in order for it to work.
Thanks!
Can you tell me what HTTP response your OLD urls are sending? 200? 301? 404?
I am interested because I have a Force.com Site where many URLs are already indexed by Google. If I apply this URL rewrite class to my Force.com Site, I want to ensure that the OLD urls are givng the index spiders a valid 301 redirect HTTP response.