function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BenjaminBBenjaminB 

Finish location: invalid page redirection. (Manually the link does in fact work)

Hi Guys,

 

Yet another question from my side. I'll quickly explain what I'm trying to do: I've created a visual flow in which employees go through a contract wizard. It creates a contract record with the information they filled in and then submits it for approval. I made it so the user has to do as few interactions as possible because we all know users can be stupid and need to have as few room as possible to forget things.

 

For all the contracts the process is finished when the wizard is done except for one contract type. For that type they need to upload a file. Since visual flow doesn't have that function I needed another way to achieve the upload.

 

What I did was to let the flow construct an url that when clicked showed them to the upload screen and also passed a return url so that they would be returned to a flow in which their submission would be submitted for approval. The url that is created in the flow looks like this:

/p/attach/NoteAttach?pid={!var_RecordID}&parentname={!ret_ContractNumber}&retURL=/flow/Simple_Approval_Tool?var_RecordID={!var_RecordID}

 And when clicked this url works perfectly. The problem is that people don't click the link, they forget and just click finish. So I had to set this url as finish location and thus came the following code. 

 

In principle it works so save your time scrutenizing the whole thing ;) The only part that doesn't work is the actual redirect to the "pp" page. I must confess though, that I do not get why the redirect works since in the VF page the reference is to {!OID} and in the controller we only have "getOID()". But it works for the "other" contracts and redirects them to the newly created (and submitted) record.

 

For the VisualForce page I have:

<apex:page Controller="ContractRequestFlowController" TabStyle="Account">
    <br/>
     <flow:interview name="Contract_Request_Wizard" interview="{!myflow}" finishlocation="{!OID}" />
</apex:page>

 And for the controller I have:

public class ContractRequestFlowController{
public Flow.Interview.Contract_Request_Wizard myFlow { get; set; }

public String getmyID() {
if (myFlow==null) return '';
else return myFlow.var_RecordID; //Retrieves var_RecordID from the flow. Important is that the var isnt private!
}

public String getRecordTypeID() {
if (myFlow==null) return '';
else return myFlow.var_ContractRecordTypeID;
}

public String getContractNumber() {
if (myFlow==null) return '';
else return myFlow.ret_ContractNumber;
}      

public String createUploadUrl() { //creates a string which is the upload url
return '/p/attach/NoteAttach?pid=' + getmyID() + '&retURL=/flow/Simple_Approval_Tool?var_RecordID=' + getmyID(); //works until I refer it to the Simple Approval Tool
}// As soon as '=/flow/Simple_Approval_Tool?var_RecordID' is added behind retURL= the system breaks.
    
public PageReference getOID(){
    PageReference p = new PageReference('/' + getmyID()); //This works like a charm!
    PageReference pp = new PageReference(createUploadUrl());//
    p.setRedirect(true);
    pp.setRedirect(true);
    if(getRecordTypeID() == '012400000005ZPM'){ //RecordTypeID of a specific type of agreement for which people need to upload a file.
   	return pp;}
    
    else{
        return p;}
}

}

 Again this works perfectly. It redirects when it needs to, it matches the record type ID perfectly. The problem lies in the fact that I cannot let it refer the retURL location to: 

/p/attach/NoteAttach?pid=' + getmyID() + '&retURL=/flow/Simple_Approval_Tool?var_RecordID=' + getmyID()

It does work If I refer it to:

/p/attach/NoteAttach?pid=' + getmyID() + '&retURL=' + getmyID()

 It fires:

Invalid Page Redirection
The page you attempted to access has been blocked due to a redirection to an outside website or an improperly coded link or button. Please contact your salesforce.com Administrator for assistance.

 

Any clue on how to fix this? Again, if I enter the link manually in the address bar it does work.

I was thinking I might redirect to a different VF page that would include an upload screen and then submit the record for approval, but I'm afraid I might run into the same issue there.

 

Any ideas would be much appreciated!

 

 

---edit---

Someone just pointed out that it might be possible to combine the fact that there is a newly created record (of the certain type) and the fact that a file was uploaded in a trigger which would then automatically submit the record for approval - thus eliminated the neccecity to set the redirect to a flow or apex that submits for approval. Any thoughts on this would also be appreciated.

sfdcfoxsfdcfox

You have two query string delimiters (?). You need to use EncodingUtil.urlEncode() function, which takes two parameters, the first being the string to encode ( '/flow/Simple_Approval_Tool?var_recordId='+getMyID() ), and the second being the character set to use (utf8). This is due to a new, recently added patch that prevents improperly formatted links from being used.

 

EditYou could also use a PageReference to acheive this same effect:

 

PageReference ref = new PageReference('/flow/Simple_Approval_Tool');
ref.getParameters().put('var_recordId',getMyID());
return ref.getUrl();

 

BenjaminBBenjaminB

Hmm now I made this:

public String createUploadUrl() { //creates a string which is the upload url
return EncodingUtil.urlEncode('/p/attach/NoteAttach?pid=' + getmyID() + '&retURL=/flow/Simple_Approval_Tool?var_RecordID=' + getmyID(), 'UTF-8');
}

 This doesn't work. I still get the invalid page redirection error. Any clues?

sfdcfoxsfdcfox

Only use EncodingUtil.urlEncode to encode actual parameters, like this:

 

return '/p/attach/NoteAttach?pid=' + EncodingUtil.urlEncode(getmyID() , 'UTF-8')+ '&retURL=' +EncodingUtil.urlEncode('/flow/Simple_Approval_Tool?var_RecordID=' + getmyID(), 'UTF-8');

A "cleaner" solution is to do this:

 

PageReference ref = new PageReference('/p/attach/NoteAttach');
ref.getParameters().putAll(new Map<String,String>{'pid'=>getMyId(), 'retURL'=>'/flow/Simple_Approval_Tool?var_RecordID=' + getmyID()});
return ref.getUrl();

This automatically formats the URL correctly, encluding URL encodings.

BenjaminBBenjaminB

I've copied and pasted both you methods but neither seems to work. Both just fire the invalid page redirection. I have no clue what is going wrong...

 

--edit--

Hmm, I tried using the following url: 

return '/p/attach/NoteAttach?pid=' + getmyID() + '&retURL=/flow/Simple_Approval_Tool';

 So that's without the second delimiter, but also then it fires the invalid page redirection error. So the problem might not be the second question mark.

 

Any thoughts?

sfdcfoxsfdcfox
retURL=/flow/Simple_Approval_Tool

 Isn't properly URL Encoded. It should be:

 

retURL=%2Fflow%2FSimple_Approval_Tool

That's the point of encoding the entire parameter: Characters such as :, /, ?, &, =, and so on must be encoded correctly or the code will fail.

 

Edit: My previous PageReference example generates the following URL:

 

/p/attach/NoteAttach?pid=12345&retURL=%2Fflow%2FSimple_Approval_Tool%3Fvar_RecordID%3D12345

Which should correctly work.