1

We started to have redirect issue, when added to url # symbol. So on backend, apex provides redirect to another page:

public ApexPages.PageReference submitRequestAction() {
   //some logic here
   ApexPages.PageReference retVal = new ApexPages.PageReference(this.returnUrl);
   retVal.setRedirect(true);

   return retVal;
}

On previous page (original page, where we want to return) was encoded in javascript with using EcmaScript.encodeURIComponent() method to (this is what i see in browser):

https%3A%2F%2ForgId%2Fapex%2FvfPageName%3Fforward%3D1%23!%2Fopportunity%2FopportunityId

then in apex ctrl with debugging i check, that i still have correct url, as this.returnUrl is:

https://orgId/apex/vfPageName?forward=1#!/opportunity/opportunityId

So when i click button, which fires submitRequestAction() im redirecting to original page with url:

https://orgId/apex/vfPageName?forward=1

We lost everything starting from # symbol.

I fixed that in vf page with adding javascript, which still using returnUrl from apex controller, but now we are avoiding Pagereference and it works fine:

<script>
    function returnButtonAction() {
       window.location.href = '{!returnUrl}';
    }
</script>

<apex:commandButton immediate="true" value="{!$Label.Button_Cancel}" oncomplete="returnButtonAction();return false;" />

I can live with this solution, but i still dont know how to fix it in apex controller. So would appreciate if you help me. Thanks.

1

I tried your code and it is working for me. Please check in different browser to see if it is a browser specific issue.

Controller

public class RedirectController {
    public PageReference submitRequestAction() {
        String returnUrl = '/apex/vfPageName?forward=1#!/opportunity/006i000000Hlb7u';
        System.debug('returnUrl '+returnUrl);
        PageReference retVal = new PageReference(returnUrl);
        retVal.setRedirect(true);
        return retVal;
    }
}

VF Page

<apex:page controller="RedirectController" action="{!submitRequestAction}" >
</apex:page>

VF vfPageName

<apex:page >
    Hello World!
</apex:page>

Screen

enter image description here

  • I tried, i put into pagereference encoded url: https%3A%2F%2ForgId%2Fapex%2FvfPageName%3Fforward%3D1%23!%2FsomeCustomObj%2Fid But then when i click return button i have error: Formula Expression is required on the action attributes. – Bogdan K Mar 9 '17 at 12:12
  • @Cooler Sorry for the overlook. I checked your code and it is working for me without any changes. Please check if it is a browser issue. – Saroj Bera Mar 9 '17 at 12:51
  • This is crazy, i checked also on testPage, it didnt work, then i changed API version of controller from 26 to 38 and now it works)))) – Bogdan K Mar 9 '17 at 13:18
  • Good to know you solved it. Put your findings as an answer and accept it so that somebody can find it useful. – Saroj Bera Mar 9 '17 at 13:20
0

Ok, so the reason is an old API version of controller. I changed it from 26 to 38 and now it works

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.