I am setting an error paremeter then redirecting to another VF page like this:

        PageReference backtosite = new PageReference('/apex/Fs_ViewSiteAddress?id='+parentId);
        System.debug('redirect url to site record: '+backtosite.getUrl());
        backtosite.getParameters().put('ERROR','You are not allowed to do that');
        return backtosite;

.. then I show the message like this:

<apex:pageMessage strength="3" severity="error" rendered="{! NOT(ISBLANK( $CurrentPage.parameters.ERROR ))}">You are not allowed to do that with this profile</apex:pageMessage>

I want my error message to be right above the related list it is genereated by, but after the re direct the focus is at the top of the page. How can I focus on the page message with the error, so the user doesn't have to scroll all the way down ?


You can use HTML fragment identifier [0] and redirect to it so browser can scroll to that area and make it visible.

To use it, generate a anchor tag with some value and specify that value in the redirect url as '/apex/Fs_ViewSiteAddress?id='+parentId +'#error-place

[0] https://en.wikipedia.org/wiki/Fragment_identifier

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.