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
kka_zzzsaikka_zzzsai 

Issue with Visual Flow - URL Redirect not working even after all the permutations tried

This is my Visualforce page

 

<apex:page standardController="Registration__c" extensions="CreateRegistration">
    <flow:interview name="Submit_a_Registration" interview="{!flowRegistration}"  finishlocation="{!FinishURL}" />
</apex:page>

 

I have trying to pick a value from Flow and form a URL.  

 

The controller is like this, 

public without sharing class CreateRegistration{

    public Flow.Interview.Submit_a_Registration flowRegistration {get;set;}
    String RegistrationObjPfix     =    '/' + Registration__c.SObjectType.getDescribe().getKeyPrefix();
    
    
    
    public CreateRegistration(ApexPages.StandardController sc){

    }

    public CreateRegistration(){

    }
    
    public String getRTypeID() {
        if (flowRegistration==null) {
            return '';
        }
        else    {
            System.debug('URL is ---'+ '/e?RecordType=' + flowRegistration.registrationrecordtypeid);    
            return '/e?RecordType=' + flowRegistration.registrationrecordtypeid;
        }
    }

    public pageReference getFinishURL()    {
         
        
        /*
        PageReference pgToFinish = flowRegistration!=null?
                                    new PageReference(RegistrationObjPfix + '/e?RecordType=' + flowRegistration.registrationrecordtypeid)
                                    :new PageReference(RegistrationObjPfix);
        */
        //PageReference pgToFinish =  new PageReference('/' + RegistrationObjPfix + '/e?RecordType=' + getRTypeID());
        PageReference pgToFinish =  new PageReference( RegistrationObjPfix + getRTypeID() );
        pgToFinish.setRedirect(true);
        return pgToFinish;
    }
    

}

 

 

The flow is supposed to do some functionality and pass the correct record type.  

 

When i see the debug log, the RTypeId is empty.  The URL clearly takes me to the record with 

/e?RecordType=

 in the end but fails to bring the recordtypeid.

 

i have tried almost all the permutations and combinations.  

 

Any help on this will be highly appreciated.  

Best Answer chosen by Admin (Salesforce Developers) 
kka_zzzsaikka_zzzsai

Hi @Rajaram

 

This is the VF page with the javascript,

 

 

<apex:page standardController="Registration__c" extensions="CreateRegistration">
    <flow:interview name="RegistrationSubmission" interview="{!flowRegistration}"  finishlocation="{!FinishURL}" rerender="loadJS"/>
    <apex:outputPanel id="loadJS">
        <script language='javascript'>
            //The Name of the Page
            var pgName        =    'createregistration';
            
            //The current URL of the page
            var currentURL    =    parent.location.href;
            
            //The Finish URL from controller and flow
            var newURL        =    '{!sFinishURL}';
            
            //If the current page contains parameters, it will be passed into the registration creation page
            if(currentURL.toLowerCase().indexOf(pgName)+pgName.length < currentURL.length) {
                currentURL        =    currentURL.substring(currentURL.toLowerCase().indexOf(pgName)+pgName.length+1,currentURL.length);
            }
            else {
                currentURL        =    '';
            }
            
            //If the new url does not contain record type, it means that the time to redirect has not come.
            //If this fails in the near future, we can always find the finish button
//and the button is available in the same page, we can invoke the submit button of the form. if(newURL.toLowerCase().indexOf("recordtype=&") == -1) { parent.location.href = newURL + '&' + currentURL; } </script> </apex:outputPanel> </apex:page>

 and the controller is,

 

/*

    Class name      :       CreateRegistration
    Author        :       kka
    Description      :       
                                1)  The controller will be used in the CreateRegistration Page that runs the flow and takes the user
                                  to the registration page accordingly.
    Version             :       v0.20
    Requested by        :       smirapuri
*/

public without sharing class CreateRegistration{
  
  //The flow that will be used for interviewing
    public Flow.Interview.RegistrationSubmission flowRegistration {get;set;}
    
    //The string that contains the Registration prefix
    String RegistrationObjPfix    =    '/' + Registration__c.SObjectType.getDescribe().getKeyPrefix();
    
    //The Finish URL where the user needs to be redirected post the flow.
    public String sFinishURL {get{
                                if (flowRegistration==null) {
                                    return ' ';
                                }
                                else    { 
                  //The user will be directed to the recordtype defined in the flow  
                  return  RegistrationObjPfix + '/e?RecordType=' + flowRegistration.RegistrationRecordTypeId + '&nooverride=1';
                                }   
                            }}
    
  /*

    Function Name    :    CreateRegistration
    Function Type    :    Constructor
    Param        :    
                  ApexPages.StandardController sc    -  The standard controller to attach the VF page to the object.
    Description      :    This funciton does nothing
    Return Type      :    void

  */
    public CreateRegistration(ApexPages.StandardController sc){

    }
  /*

    Function Name    :    CreateRegistration
    Function Type    :    Constructor
    Param        :    
                  None
    Description      :    This funciton does nothing
    Return Type      :    void

  */
    public CreateRegistration(){

    }
    
  /*

    Function Name    :    getFinishURL
    Function Type    :    Redirecter
    Param        :    
                  None
    Description      :    This function will be used to compose the Finish URL and assign it to the Finish button in the flow.
    Return Type      :    void

  */
    public pageReference getFinishURL()    {
                 
        /*
        PageReference pgToFinish = flowRegistration!=null?
                                    new PageReference(RegistrationObjPfix + '/e?RecordType=' + flowRegistration.RegistrationRecordTypeId)
                                    :new PageReference(RegistrationObjPfix);
        */
        //Create a page reference that needs to be attached to the flow
        PageReference pgToFinish =  new PageReference( sFinishURL );
        
        //Redirect the VF page
        pgToFinish.setRedirect(true);
        return pgToFinish;
    }
    

}

 

Please note that the Flow has got a a screen element in the end.  That screen will exist only for few seconds.  The screen element  will have words like, "If you do not see the screen take you to the concerned record, please click finish" or something like that.

All Answers

RajaramRajaram

What happens on your page when you alter your VF to the following:

 

<apex:page standardController="Registration__c" extensions="CreateRegistration">
<flow:interview name="Submit_a_Registration" interview="{!flowRegistration}" finishlocation="{!FinishURL}" />

Record Type ID: {!RTypeID}
</apex:page>

 

Do you see the record type ID?

DarrellDDarrellD

I appear to be having a very similar issue. Was asked to open a case on it last week, which I did but the proposed answer doesn't seem to be working. I too get a null value when passing back to the URL.  The addition I'll add, and not clear if original poster had same, is that my variable is coming back from a subflow and not the Master Flow.

RajaramRajaram

Ah yes.. when referencing <flow>.<variable> in your controller, it will work ONLY with the variable values in the main flow (The flow matching the type of <flow>)

 

However, no fear! With the Winter '13 release, we added a new method called GetVariableValue to the FLow object, which will get the value of subflow variables.

 

So you need to switch your call from

flowRegistration.registrationrecordtypeid

 

to 

 

flowRegistration.getVariableValue("registrationrecordtypeid")

 

 

Hope this helps..

 

I will work on a blog post for this ..

 

 

 

 

kka_zzzsaikka_zzzsai

Hi @Rajaram

 

I did that too and that returned empty string.

 

I came to know through salesforce that the flow needs to have a Finish flow to bring the data.  But, in my case I have branched such that the flow might come into an end with in the first 1 step or 2nd step or 3rd step depending upon the choices the user makes.

 

Yes, I do not have 1 screen/step where all the decisions converge. 
So, when the user clicks next, the flow might have already ended based on his choice selected in the first screen.

 

So, what I did was, I created a step/screen that converged all the steps.  Then invoked the flow in my visualforce page and the flow variable was coming up with the necessary value.  And, I wrote a javascript in a output panel that redirects the page to the necessary URL when the flow returns a valid recordType.  With this, I can also route the entire flow to an external website as well.

 

Is there any other way to do this without having the final converged screen and javascript?

 

If you want me to post, the code, i can do that.

RajaramRajaram

Yes.. if you have a flow without a screen element in the end, you may encounter the issue of variables being pased back to VF. Lemme check on this with devs.

Would defenitely like to see your js to get a better understanding on it..

 

 

kka_zzzsaikka_zzzsai

Hi @Rajaram

 

This is the VF page with the javascript,

 

 

<apex:page standardController="Registration__c" extensions="CreateRegistration">
    <flow:interview name="RegistrationSubmission" interview="{!flowRegistration}"  finishlocation="{!FinishURL}" rerender="loadJS"/>
    <apex:outputPanel id="loadJS">
        <script language='javascript'>
            //The Name of the Page
            var pgName        =    'createregistration';
            
            //The current URL of the page
            var currentURL    =    parent.location.href;
            
            //The Finish URL from controller and flow
            var newURL        =    '{!sFinishURL}';
            
            //If the current page contains parameters, it will be passed into the registration creation page
            if(currentURL.toLowerCase().indexOf(pgName)+pgName.length < currentURL.length) {
                currentURL        =    currentURL.substring(currentURL.toLowerCase().indexOf(pgName)+pgName.length+1,currentURL.length);
            }
            else {
                currentURL        =    '';
            }
            
            //If the new url does not contain record type, it means that the time to redirect has not come.
            //If this fails in the near future, we can always find the finish button
//and the button is available in the same page, we can invoke the submit button of the form. if(newURL.toLowerCase().indexOf("recordtype=&") == -1) { parent.location.href = newURL + '&' + currentURL; } </script> </apex:outputPanel> </apex:page>

 and the controller is,

 

/*

    Class name      :       CreateRegistration
    Author        :       kka
    Description      :       
                                1)  The controller will be used in the CreateRegistration Page that runs the flow and takes the user
                                  to the registration page accordingly.
    Version             :       v0.20
    Requested by        :       smirapuri
*/

public without sharing class CreateRegistration{
  
  //The flow that will be used for interviewing
    public Flow.Interview.RegistrationSubmission flowRegistration {get;set;}
    
    //The string that contains the Registration prefix
    String RegistrationObjPfix    =    '/' + Registration__c.SObjectType.getDescribe().getKeyPrefix();
    
    //The Finish URL where the user needs to be redirected post the flow.
    public String sFinishURL {get{
                                if (flowRegistration==null) {
                                    return ' ';
                                }
                                else    { 
                  //The user will be directed to the recordtype defined in the flow  
                  return  RegistrationObjPfix + '/e?RecordType=' + flowRegistration.RegistrationRecordTypeId + '&nooverride=1';
                                }   
                            }}
    
  /*

    Function Name    :    CreateRegistration
    Function Type    :    Constructor
    Param        :    
                  ApexPages.StandardController sc    -  The standard controller to attach the VF page to the object.
    Description      :    This funciton does nothing
    Return Type      :    void

  */
    public CreateRegistration(ApexPages.StandardController sc){

    }
  /*

    Function Name    :    CreateRegistration
    Function Type    :    Constructor
    Param        :    
                  None
    Description      :    This funciton does nothing
    Return Type      :    void

  */
    public CreateRegistration(){

    }
    
  /*

    Function Name    :    getFinishURL
    Function Type    :    Redirecter
    Param        :    
                  None
    Description      :    This function will be used to compose the Finish URL and assign it to the Finish button in the flow.
    Return Type      :    void

  */
    public pageReference getFinishURL()    {
                 
        /*
        PageReference pgToFinish = flowRegistration!=null?
                                    new PageReference(RegistrationObjPfix + '/e?RecordType=' + flowRegistration.RegistrationRecordTypeId)
                                    :new PageReference(RegistrationObjPfix);
        */
        //Create a page reference that needs to be attached to the flow
        PageReference pgToFinish =  new PageReference( sFinishURL );
        
        //Redirect the VF page
        pgToFinish.setRedirect(true);
        return pgToFinish;
    }
    

}

 

Please note that the Flow has got a a screen element in the end.  That screen will exist only for few seconds.  The screen element  will have words like, "If you do not see the screen take you to the concerned record, please click finish" or something like that.

This was selected as the best answer
Vivek SalveVivek Salve
Hi @kka_zzzsai

I have created a custom button on Opportunity. The button when click calls the main flow. The main flow has many subflows depending on the radio buttons we select.

Now I have 2 visualforce page created. 1st page embeds the main flow and opens when opportunity custom button is clicked. Once I select my choice, it redirects to subflow. My second page calls when the main flow is finished that is at the end of the flow. But in my second flow I am not able to get the parameters which I pass from the first page . The page URL only redirect with the 2nd vf page name. If I enter the url by passing '/apex/pagename?varable='+id' then am getting a null value.

Please let me know how can I get the 2nd variable value in 2nd page. Also in my controller class I am getting both main flow and subflow variables like:
public Flow.Interview.RFPQuestionnaire mainFlow{get;set;} //main flow
public Flow.Interview.MS_X_Screen fileUpload {get;set;} //subflow


 
kka_zzzsaikka_zzzsai
I have never tried anything like this. Would require some analysis.
Vivek SalveVivek Salve
How did you resolve your issue.. In my last screen before finish I am able to get the values on the screen but when I click on next button and boolean variable on previous screen is true then it will display the 2nd page upload page block and with that it passes the parentid parameter. But when the UploadPage is open in url the parameters are gettings as null value.