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
jpb@uhcjpb@uhc 

Set finishlocation for Flow to be record created by Flow

We have created a flow that creates an Opportunity and we want the "finishlocation" of the flow, where they end up when they click "Finish", to be the newly created Opportunity. I know that we will have to create a VF page and controller to pass the OpptyID (once created) back to the VF page and set as the finishlocation, but can't figure out how to do it. Any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
jpb@uhcjpb@uhc

Sorry, for the late response, but i stumbled upon the resolution myself. Here is the code:

 

VF Page -

<apex:page Controller="OpptyFlowController" TabStyle="Opportunity">
    <br/>
    <flow:interview name="CreateOppty" interview="{!myflow}" finishlocation="{!OID}" />
</apex:page>

 Here is the Class -

public class OpptyFlowController {

public Flow.Interview.CreateOppty myFlow { get; set; }

public String getmyID() {
if (myFlow==null) return '';
else return myFlow.OpptyID;
}

public PageReference getOID(){
PageReference p = new PageReference('/apex/opportunityProductEntry?id=' + getmyID() + '&addTo=' + getmyID() + '&retURL=%2F006%2Fe&sfdc.override=1');
p.setRedirect(true);
return p;
}

}

 

All Answers

AmitSahuAmitSahu

You can create a button (Finish) , a VF page and  a controller.

 

Override the view page of opportunity wth the VF page you will create.

 

Once the Opp is created the record will go to your VF page and then you can click on the Button to call finish from the controller.

Abhay AroraAbhay Arora

Basically let the finish button be the action handler for the creation of the opportunity as

 

On click of finish Save the opportunity

redirect the user to the Detail page of the Newly created opportunty on Click of Finish or you can send him to a page saying that the opportunity has been created

Abhay AroraAbhay Arora

Please mark this as solved if your problem is solved

jpb@uhcjpb@uhc

Sorry, for the late response, but i stumbled upon the resolution myself. Here is the code:

 

VF Page -

<apex:page Controller="OpptyFlowController" TabStyle="Opportunity">
    <br/>
    <flow:interview name="CreateOppty" interview="{!myflow}" finishlocation="{!OID}" />
</apex:page>

 Here is the Class -

public class OpptyFlowController {

public Flow.Interview.CreateOppty myFlow { get; set; }

public String getmyID() {
if (myFlow==null) return '';
else return myFlow.OpptyID;
}

public PageReference getOID(){
PageReference p = new PageReference('/apex/opportunityProductEntry?id=' + getmyID() + '&addTo=' + getmyID() + '&retURL=%2F006%2Fe&sfdc.override=1');
p.setRedirect(true);
return p;
}

}

 

This was selected as the best answer
oodood

if we don't want to click finish button how redirectly to detail page .

BenPBenP

Any hints on a test class for this controller?  This solution works brilliantly, but I'd like to cover the testing.

sddodsonsddodson

 

 

Can you highlight which spots we would need to fill in with the name of our own flow names and variables?

 

Thank you!

sekharasekhara

Hi, 

 

In Below code from where we are getting Opptyid .

ccliburn1.3906015844179573E12ccliburn1.3906015844179573E12
In the following part of the code:

PageReference p = new PageReference('/apex/opportunityProductEntry?id=' + getmyID() + '&addTo=' + getmyID() + '&retURL=%2F006%2Fe&sfdc.override=1');

To what does ''/apex/opportunityProductEntry   refer
Also, what is  e&sfdc.override=1  ?
vleandrovleandro
Thank you!  I've been working a number of solutions for a while now and finally was able to get this to work the way I want it to! 
Lindsey ColvinLindsey Colvin
If there are 2 finish locations, 1 that asks them to finish and contact support due to their need being an urgent priority 1 need, and the second being after a case is created, is there a way to get the first finish to take them back home, while the 2nd takes them to the created case?  When I click the 1st finish (since there is NOT a created case at that stage of the flow), it takes me to the:

URL No Longer Exists
You have attempted to reach a URL that no longer exists on salesforce.com

screen, with a return URL of salesforce.com/null.

Any help would be extremely appreciated!
bathybathy
hi Guys,

Can youhelp with the test class for this extensions??

thanks,
Derek Davis 7Derek Davis 7
Thank you all for providing! This is very helpful! Could anyone assist with Test Class?
 
Aaron Persich 9Aaron Persich 9
Has this been resolved?  If so how did you do it?  I am working on the exact samething and cannot figure out how to set the finish location to the newly created opp.
isalewisalew
Apparently there is a known issue with navigating to new records if create is the last step in the flow. See details below and please vote for the idea to make this easier!

Known Issue
Not able to get record IDs from Flow to VisualForce if create record is the last step in flow
https://developer.salesforce.com/forums/?id=906F000000097pVIAQ

Idea
Flow Designer needs a simple way to "end" a flow by navigating to a record
https://success.salesforce.com/ideaView?id=08730000000ipeVAAQ
Prachi KPrachi K
Hi Guys,

I have seen several blogs regarding setting the landing page for flow to the newly created record using VF page and apex controller, but not sure what exactly should be the code for the custom button from where this flow is being called. I have a scenario wherein I need to create an opportunity after clicking on the "Create Opportunity" button on case object which should land to the newly created opportunity record page when I click on "Finish" button.

Here is the code for reference:
VF Page:
<apex:page controller="OpptyFlowController2"> <flow:interview name="TestOpp" interview="{!flowInstance}" finishLocation="{!finishLocation}"/> </apex:page>

Apex Controller:
public class OpptyFlowController2 {

// Instanciate the Flow for use by the Controller - linked by VF interview attribute
  public Flow.Interview.TestOpp flowInstance {get;set;}
  PageReference pageRef;
  // Set the page reference accessor methods
  public PageReference finishLocation {
    get {
      pageRef = new PageReference('/' + newRecordId);
      pageRef.setRedirect(true);
      return pageRef;
    }
    set { pageRef = value; }
  }

  // Set the accessor methods for the flow output variable
  public String newRecordId {
    get {
      String strTemp = '';

      if(flowInstance != null) {
        strTemp = string.valueOf(flowInstance.getVariableValue('varOppId'));
      }
      return strTemp;
    }

  set { newRecordId = value; }
  }
}

Custom Detail Page Button "Create Opportunity":
/flow/TestOpp?varAccountId={!Case.AccountId}&varCaseID={!Case.Id} 
&varOppOwner2={!Account.OwnerId}&retURL=/apex/CreateOppFromSRPage2

I am not sure what exactly shoule be mentioned in the return URL for this custom button. Could anyone please help with that?
Custom Detail Page Button "Create Opportunity":
/flow/TestOpp?varAccountId={!Case.AccountId}&varCaseID={!Case.Id}  &varOppOwner2={!Account.OwnerId}&retURL=/apex/CreateOppFromSRPage2

Here "varOppId" is the output type variable which I created in my Flow to capture the Opportunity record ID

Thank you!
Prachi KPrachi K
Hi @Mayank Srivastava,
This is regarding flow finish landing to the newly created record. I have "Opportunity__c" (lookup field) on case object. Also there is a service_request__c (lookup to case) on Opportunity object. My requirement is I need to create an opportunity after clicking on the "Create Opportunity" button on case object which should land to the newly created opportunity record page when I click on "Finish" button. Though I am able to land it to the case detail page from where I am creating opportunity but not able to make it landing to the newly created opportunity record.
Here is the URL of my "Create Opportunity" button on case object-

/flow/CreateOppFromSR?varAccountId={!Case.AccountId}&varCaseID={!Case.Id}&varCaseNumber={!Case.CaseNumber}&varProductId={!Case.ProductId}&retUrl =/{!Case.Opportunity__c}

Any help would be greatly appreciated.

Regards,
Prachi
Vimarsh SaxenaVimarsh Saxena
Hi jpb@uhc

My VF page still doesn't redirect to the new record created by flow. Here is my VF Page and Controller:

VF Page

User-added image

Controller

User-added image

Can you suggest something please.

Thank You!
AthiSachiAthiSachi
Hello everyone,

Is there any solution for finishpage. It worked great when I have extension controller. However I couldn't create test class. Can anyone help with test class thanks.

<apex:page standardController="GW_Volunteers__Volunteer_Job__c" tabStyle="GW_Volunteers__Volunteer_Job__c" extensions="FlowRedirectController"> <flow:interview name="GIGI_SyncProgVolToPlay_ProgVolJob1" interview="{!redirectTo}" finishLocation="{!finishLocation}" > <apex:param name="VarId" value="{!GW_Volunteers__Volunteer_Job__c.Id}"/> <apex:param name="AlreadySynced" value="{!GW_Volunteers__Volunteer_Job__c.SyncedSuccessfully__c}"/> <apex:param name="VarPrgName" value="{!GW_Volunteers__Volunteer_Job__c.Name}"/> </flow:interview> </apex:page>


Extension class:
Public class FlowRedirectController{

    public FlowRedirectController(ApexPages.StandardController controller) {

    }

    Public Flow.Interview.GIGI_SyncProgVolToPlay_ProgVolJob1 redirectTo {get; set;}

    public FlowRedirectController() {
        Map<String, Object> redirectURL = new Map<String, Object>();
        
        //vFinishLocation is the name of a variable from your Flow containing the Id of your newly created Opportunity
        redirectURL.put('VarId','https://gigisplayhouse--volprogvf.cs45.my.salesforce.com/');
        redirectTo = new Flow.Interview.GIGI_SyncProgVolToPlay_ProgVolJob1(redirectURL);
    }

    Public PageReference getFinishLocation(){
     string strID = ApexPages.currentPage().getParameters().get('Id');
        String finishLocation;
        if(redirectTo != null) {
            finishLocation = (string) redirectTo.getVariableValue('VarId');
        }
        else
        {
        finishLocation=strID;
        }
        PageReference send = new PageReference('/' + finishLocation);
        send.setRedirect(true);
        return send;
    }
}

Test class:
@isTest
private class FlowRedirectControllerTest{

    static testmethod void SetVariablesTests() {
    
    
      //Insert Campaign
    Campaign sCmp = new Campaign(Name='TestClassCamp',Status='Active');
    insert sCmp;
     System.debug('inserted campaigns . athi ' );
   
    // Retrieve the new campaign
    sCmp = [SELECT Id,Name FROM Campaign WHERE Id =:sCmp.Id LIMIT 1];
 
 
         //Insert prog job
    GW_Volunteers__Volunteer_Job__c vol=new GW_Volunteers__Volunteer_Job__c(Name='TestJob', GW_Volunteers__Campaign__c =sCmp.id, GW_Volunteers__Description__c ='Hellow', GW_Volunteers__Display_on_Website__c=true);
        insert Vol;
    // System.debug('inserted  Jobs. athi ' );
   
    // Retrieve the new prog Job
  vol = [SELECT Id,Name, GW_Volunteers__Campaign__c, GW_Volunteers__Display_on_Website__c FROM GW_Volunteers__Volunteer_Job__c WHERE Id =:vol.Id LIMIT 1];
     Test.startTest();
        //VFFLow is the name of the VisualForce page which you create
        PageReference pageRef = Page.GIGI_SyncProgJobToPlayVF;
        Test.setCurrentPage(pageRef);
        System.currentPageReference().getParameters().put('Id',Vol.Id);
        FlowRedirectController testCtrl = new FlowRedirectController();
        testCtrl.redirectTo = new Flow.Interview.GIGI_SyncProgVolToPlay_ProgVolJob1(new Map<String, Object>());
        testCtrl.redirectTo.start();

        testCtrl.getFinishLocation();
        Test.StopTest();
      //  System.assertEquals(testCtrl.getFinishLocation().getUrl(), 'https://gigisplayhouse--volprogvf.cs45.my.salesforce.com/');
    }
}

Thanks in advance