2

Problem: Using a URL Rewriter class causes failure of a View override page

Background: We have a community portal with a custom Visualforce application. We have overridden the View action on Case with a Visualforce page.

Within our application, we have a Chatter publisher widget where we can @mention portal users. When the user receives the notification email from Salesforce, they can click on the link, login to the portal, and they'll be presented with the record detail within the VF application. We do have a custom login page for this portal.

Current Situation: This was all working fine until we implemented an URL Rewriter class for the community site. Now, we have different problems in production vs sandbox. In production, after the portal user logs in, he sees an error "Error occurred while loading a Visualforce page. Formula Expression is required on the action attributes." In the sandbox, we don't get this error, but instead the app's custom error handling kicks in and throws a generic error page.

If I remove the URL rewriter, then it works fine.

I suspect it has to do with the View override page, which looks like this:

<apex:page standardController="Case" extensions="SettingsExtension"
                     action="{!IF(settings.Deactivate_View_Overrides__c, URLFOR($Action.Case.View, Case.Id, null, true),
                                    URLFOR($Page.ViewClientOverview, null, [id=Case.HC_Id__c, caseId=Case.Id], true))}"
                     cache="false">
    <apex:outputPanel style="display:none;" >
            {!case.HC_Id__c}
    </apex:outputPanel>
</apex:page>

The URL Rewriter is only checking for a specific inbound URL format -- it is not changing any "output" URLs.

global class HL_UrlRewriter implements Site.UrlRewriter {
    String LIVE_LINK = '/shortener/';
    String redirectBase = '/My_Redirector?url=';
    String redirectUrl;

    global PageReference mapRequestUrl(PageReference original) {
        String theUrl = original.getUrl();
        if (theUrl.startsWith(LIVE_LINK)) {
            return processLiveLink(theUrl);
        }
        return null;
    }

    // This method must exist but we don't use it.
    global List<PageReference> generateUrlFor(List<PageReference> salesforceUrls) {
        return salesforceUrls;
    }

    private PageReference processLiveLink(String theUrl) {
        // the code here does not run during situation described in this post.
    }
}

According to this blog entry,

Any URL which contains a Salesforce Object ID ... Salesforce’s standard UI will kick in and take control, so if you have a URL like

✘/routeto/a00N000000E23Zs

Salesforce is going to kick in and take that request, sending it to the standard page handler before it gets to your re-writer

However, the Chatter link that I get in the email has several parameters after the ID, like s1oid, s1nid, OpenCommentForEdit, etc.

So I have a few questions:

  1. If there are parameters after the object ID, will Salesforce still take control and skip the URL Rewriter?

  2. If the URL rewriter is indeed being skipped, why is it affecting the override page?

  3. Is there a way to get more information in the debug log to see what's happening in the action parameter of the override page? I've already set Finer on Visualforce but I didn't get any clearer detail from

  • Just an idea that popped into my head while reading your qestion, have you considered something like encrypting the ID in the url so that salesforce doesn't think it's an Id? doing something simple like taking the key prefix and putting it into a different param should be enough something like key=005&id=0000000XXXX I'm not 100% sure if that will work but it's something you can test while you wait for a real answer. – gNerb May 14 '18 at 19:33
  • 1
    Thanks, but I don't think that can be done because the email and link are generated by the Salesforce Chatter notification process and can't be modified. I am considering rewriting the override page to use a PageReference action in the controller rather than URLFOR in the page. – David Cheng May 14 '18 at 20:07
  • If you leave the rewrite class in place but turn off the view override, what happens? Just curious - I wonder if the rewriter class is having some unexpected side effect that's throwing off Visualforce... – Benj May 18 '18 at 21:18
1

I fixed this by writing a controller extension with a method to do a page redirect and I got rid of the URLFOR in the VF page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.