0

When my controller returns null in a pageReference method, I lose my friendlyURL.

URLReWriter:

global without sharing class URLRewriter implements Site.UrlRewriter {

    global PageReference mapRequestUrl(PageReference myOriginalUrl){
        String url = myOriginalUrl.getUrl();
        String name;
        system.debug('Orginal URL is: '+url);
        if(url.equalsignorecase('/RSAP/help')){
            name = 'PBS_AAAP_Help';
        } else if(url.equalsignorecase('/RSAP/Help?Type=lop')){
            name = 'PBS_AAAP_Help?Type=lop';
        } else if(url.equalsIgnoreCase('/RSAP/UserRegistration')) {
            name = 'PBS_AAAP_UserRegistration';
        } else if(url.equalsIgnoreCase('/RSAP/userprofile?Type=lop')){
            name = 'PBS_AAAP_UserProfile?Type=lop';
        } else if(url.equalsIgnoreCase('/RSAP/UserProfile')) {
            name = '/PBS_AAAP_UserProfile';
        } else if(url.startsWithIgnoreCase('/AAAP/LOP_offerform1364')) {
            name = url.remove('/AAAP');
        } else if(url.startsWithIgnoreCase('/AAAP/LOP_offerform1217')) {
            name = url.remove('/AAAP');
        } else if(url.startsWithIgnoreCase('/AAAP/') && !url.contains('PBS_AAAP_')){
            name = url.remove('/AAAP/');
            name = '/PBS_AAAP_'+name;
        } else if (url.startsWithIgnoreCase('/RSAP/')){
            name = url.remove('/RSAP/');
            name = 'PBS_LOP_'+name;
        }  else {
            name = url;
        }
        system.debug('Final name is: '+name);
        PageReference pr = new PageReference(name);
        system.debug('PageReference is: '+name);
        return pr;
    }
    global List<PageReference> generateUrlFor(List<PageReference> mySalesforceUrls){
        return mySalesforceUrls;
    }
}

When this piece of code executes:

if (offerattachment.PBS_AAAP_Attachment_Type__c == null) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Attachment Type is required.'));
            return null;  
        }

it shows the error, but I lose my friendly URL. If I handle the URL explicitly in the rewriter class, then I lose the error msg. Is there any way I can show the error without losing the friendly URL?

1 Answer 1

0

Just closing the loop here.. I ended up using jQuery to detect unfriendly URLs and make them friendly on the page.

You must log in to answer this question.

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