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
Gleb GawriljukGleb Gawriljuk 

Redirecting Visual Flows in Lighting Browser and Salesforce App

Hey everyone,

we have a flow which we invoke by a Visualforce page to redirect it to an opportunity record after the flow finishs:
<apex:page standardController="Opportunity">   
    <flow:interview name="Opportunity__Flow" finishLocation="/{!Opportunity.Id}">
        <apex:param name="recordId" value="{!Opportunity.Id}"/>
    </flow:interview>   
</apex:page>

Now, this does not work in the Salesforce mobile app. Salesforce hinted me to:
https://developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/salesforce1/vf_dev_best_practices_navigation.htm

Now my Visualforce page looks like:
<apex:page standardController="Opportunity">   

    <flow:interview name="Opportunity_Flow" finishLocation="sforce.one.navigateToSObject(\'' + {!Opportunity.Id} + '\')';">
        <apex:param name="recordId" value="{!Opportunity.Id}"/>
    </flow:interview>
    
    <script type="text/javascript">
        function getRecordURL() {
            var recordURL = 'sforce.one.navigateToSObject(\'' + '{!Opportunity.Id}' + '\')';
            return recordURL;
        }
    </script>   
</apex:page>

I tried it both as a function and dirctly in the finishLocation-parameter. Both lead to the error:
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. For more information, see Insufficient Privileges Errors. 

Click here to return to the previous page.

Does anyone have experience with flow redirections in the Salesforce mobile app? 

Kind regards,
Gleb

 
Miriam GutiérrezMiriam Gutiérrez
Hi Gleb!!

Did you find a solution? I'm experiencing the same issue "Invalid page redirection".
I want to return to the record page from where the flow was called (in the same window/tab, we don't want a new window to be opened). 

My VF page looks like this:
<apex:page standardController="MyCustomObject" tabStyle="MyCustomObject__c" extensions="MyCustomObjectExt">
        <flow:interview name="MyFlow" finishLocation="{!callfinishFlow}">
        <apex:param name="recordId" value="{!myfield__c.Id}"/>
    </flow:interview>
    
    <script type="text/javascript">
        function finishFlow(){
            if((typeof sforce != 'undefined') && sforce && (!!sforce.one))
                  sforce.one.navigateToSObject(myfield__c.Id);
                  //sforce.one.navigateToURL("/"+myfield__c.Id);
            else
                  //window.location.assign = "/"+{!myfield__c.Id};
                  window.location = "/"+myfield__c.Id;

         }  
    </script>
</apex:page>



As I'm already using a standard controller, I can't use a controller to redirect to the record page. So, I'm using an extension which calls to my javascript code. If we are in SF1 then, sforce.one should fire. If we are in classic then, window.location should fire.

The extension code is:
 
public class MyCustomObjectExt{
   
    public string callfinishFlow{get;set;}
    
    public MyCustomObjectExt(ApexPages.StandardController myStdController)
    {
      callfinishFlow='<script> finishFlow(); </script>';
    }
}

Thanks for your help!
Miriam​