0

I have a visualforce page that I'm using to redirect a user to a second and final visualforce page in an attempt to bypass a CSRF Token request (it's from a managed package). I can't seem to get the parameters to pass correctly to the final visualforce page. From the debug it appears that the controller is assigning the variables correctly, but it doesn't look like the pagereference method isn't pushing the parameters to the redirect visualforce page.

I have a suspicion that the URLFOR() address is not formatted correctly, which is where the parameters are getting stuck.

Redirect Visualforce page:

<apex:page controller="Screen_Flow_Redirect" showHeader="true">
<apex:slds />
<script src="/soap/ajax/55.0/connection.js" />
<script type="text/javascript">
    function init() {
       redirectURL = "{!URLFOR(IF($Site.prefix == '/s','/apex/dfsle__gendocumentgenerator',$Site.Prefix +'/apex/dfsle__gendocumentgenerator'), null,[sId='sId',templateId=''+'templateId'+'',recordId='recordId',title='title'])}";    
        if (sforce && sforce.one) {
        sforce.one.navigateToURL(redirectURL);
        } else {
        document.location.assign(redirectURL);
        }
    }
    init();
</script>
</apex:page>

Controller:

global without sharing class Screen_Flow_Redirect {

public String title = 'Send with Docusign';
public String recordId = ApexPages.currentPage().getParameters().get('recordId');
public String sId = ApexPages.currentPage().getParameters().get('sId');
public Id templateId = ApexPages.currentPage().getParameters().get('templateId');

public String sendWithRedirect(Id templateId, String sId, String recordId, String title) {
    PageReference pr = Page.VF_Redirect;
    pr.getParameters().put('sId',sId);
    pr.getParameters().put('templateId',templateId);
    pr.getParameters().put('recordId', recordId);
    pr.getParameters().put('title', title);
    return pr.getUrl();
  }
}

Error message: enter image description here I am attempting to replicate the feature of a detail page button, this is what launches the page I need and what the URLFOR() function in my VF page should redirect to. enter image description here

2 Answers 2

1

You're passing in the the literal string templateId, which isn't a valid Id. Don't put quotes around the parameters when you mean to use variables. URLFOR should automatically create the correct prefixes if you simply use the $Page global variable:

redirectUrl = "{!URLFOR(
  $Page.dfsle__gendocumentgenerator, 
  null, 
  [
    sId=sId,
    templateId=templateId,
    recordId=recordId,
    title=title
  ])}";

Edit: You need to have getters and setters for Visualforce to see the variables.

public String title = 'Send with Docusign';
public String recordId = ApexPages.currentPage().getParameters().get('recordId');
public String sId = ApexPages.currentPage().getParameters().get('sId');
public Id templateId = ApexPages.currentPage().getParameters().get('templateId');

Should be:

public String title { get; set; }
public String recordId { get; set; }
public String sId { get; set; }
public Id templateId { get; set; }

Here's the full class updated to work with your markup:

public inherited sharing class Screen_Flow_Redirect {
    public String title { get; set; }
    public String recordId { get; set; }
    public String sId { get; set; }
    public Id templateId { get; set; }
    public Screen_Flow_Redirect() {
        title = 'Send with Docusign';
        recordId = ApexPages.currentPage().getParameters().get('recordId');
        sId = ApexPages.currentPage().getParameters().get('sId');
        templateId = ApexPages.currentPage().getParameters().get('templateId');
    }
    public String sendWithRedirect(Id templateId, String sId, String recordId, String title) {
        PageReference pr = Page.VF_Redirect;
        pr.getParameters().put('sId',sId);
        pr.getParameters().put('templateId',templateId);
        pr.getParameters().put('recordId', recordId);
        pr.getParameters().put('title', title);
        return pr.getUrl();
    }
}
4
  • Thank you for the help. When I go to remove the quotes or use your code above the visualforce page throws these errors for each variable, "Create Apex property 'Screen_Flow_Redirect.sId'" and "Create Apex method 'Screen_Flow_Redirect.getSId'". If I choose the first it says its a duplicate, if I choose the second it creates this line of code in the controller, "public String getSId() {return null; } and the error disappears, but when I run the process again I only get a blank screen no more error page like above.
    – KB2021
    Commented Dec 12, 2022 at 14:50
  • @KB2021 Yeah, the properties need to be defined with a getter and setter. See my edit for the latest version.
    – sfdcfox
    Commented Dec 12, 2022 at 15:13
  • Made the update to the class, but still getting a blank page, from the debug log it appears the redirect URL isn't being returned/launched to.
    – KB2021
    Commented Dec 12, 2022 at 15:30
  • I think it's because the sendWithRedirect() method isn't being called.
    – KB2021
    Commented Dec 12, 2022 at 16:21
0

Everything above worked except I structured my apex page like this, which finally got me to the functionality I needed.

<apex:page controller="Screen_Flow_Redirect" showHeader="true">
<apex:slds />
<script src="/soap/ajax/55.0/connection.js" />
<script type="text/javascript">
   function init() {
      redirectURL = "{!URLFOR(IF($Site.prefix == '/s','/apex/dfsle__gendocumentgenerator',$Site.Prefix +'/apex/dfsle__gendocumentgenerator'), null,[sId=sId,templateId=templateId,recordId=recordId,title=title])}";    
      if (sforce && sforce.one) {
      sforce.one.navigateToURL(redirectURL);
      } else {
      document.location.assign(redirectURL);
      }
   }
   init();
</script>
</apex:page>

You must log in to answer this question.

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