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
ryepes15ryepes15 

Visualforce page not returning correct page

Contract Object
Fulfillment Object (custom object)

When an opportunity gets closed won, a contract gets created via a button.
What i want is the a fulfillment record to also create automatically when the contract gets created
i also what the end screen to be the edit screen of the contract that was created

What i have so far: In my FinalConfg sandbox i have the following:
Custom Button on the opportunity: Create Contract
Visual Workflow:Called: "Auto Create Fulfillment"
Visualforce Page called: "CreateContract"
Visualforce Class called: "OpportunityFlowControl"

Everything seems to work fine except for the end screen, it does not return me to the edit screen of the Contract

Here is the code to my class:
public class OpportunityFlowControl {


    private final opportunity oppty;
    private final contract contract;
    public OpportunityFlowControl(ApexPages.StandardController stdController) {
      this.oppty = (Opportunity)stdController.getRecord();
    }
   
    Boolean testmode = Test.isRunningTest();


  //Calls referenced Flow below
  public Flow.Interview.Auto_Create_Fulfillment flAutoCreate { get; set; }

  //Gets Id of variables below from flow
  public String getopptyID() {
    if (flAutoCreate==null || ( testmode == true )){
     return '';
    }else{
      System.Debug('OpptyID:' + flAutoCreate.OpptyID);
      return flAutoCreate.OpptyID; //need test
    }
   
  }
 

  public String getcontractID() {
    if (flAutoCreate==null || ( testmode == true )) {
      return '';
      } else {
        System.Debug('ContractId:' + flAutoCreate.ContractCreate);
        return flAutoCreate.ContractCreate; //need test
    }
  }
 
  //Used for Flow finish location
  public PageReference getFinishPage(){
    if (flAutoCreate==null || ( testmode == true )) { return new PageReference('');}
   
    // need test case
    if(flAutoCreate.ContractCreate == null || ( testmode == true )){ 
    Contract cont;
    cont = [Select ID,Name,ContractNumber, createdDate from Contract where Opportunity__c =: this.oppty.Id Order by createdDate desc Limit 1];
      PageReference p = new PageReference('/' + cont + '/e');
      p.setRedirect(true);
      system.debug('Page Contract: ' + p);
      return p;
   
     
     
    }else {
   /* PageReference p = new PageReference('/' + getopptyID());
      p.setRedirect(true);
      system.debug('Page Opportunity: ' + p);
      return p; */
     
      Contract cont;
    cont = [Select ID,Name,ContractNumber, createdDate from Contract where Opportunity__c =: this.oppty.Id Order by createdDate desc Limit 1];
      PageReference p = new PageReference('/' + cont + '/e');
      p.setRedirect(true);
      system.debug('Page Contract: ' + p);
      return p;
    }
  }

 
}
Ramu_SFDCRamu_SFDC
When you say it is not redirecting back to contract edit page is it ending in the last page of flow? if so, you can override that by setting finish behavior as explained in the below article

https://help.salesforce.com/HTViewHelpDoc?id=vpm_admin_onfinish.htm&language=en_US