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
Gary PayneGary Payne 

How to display a newly created record from process builder?

A custom object, called "RFP", is created via process builder when the Opportunity is saved with a Stage = "Proposal".  The RFP record is created but it is not displayed for editing.  The user must go to the related list and click on the RFP name and then the Edit button to display the RFP record, which is a VF page.  What needs to be created in order for the RFP record to be immediately displayed in Edit Mode, instead of displaying the Opportunity Detail screen after the RFP has been created?
KaranrajKaranraj
You can't do this with the process builder or without writing code. Then only approach for this scenario is, who have to do it via visualforce page.

1. Create a custom visualforce page using standard controller for creating and editing the record.
2. Override the 'Save' button in your visualforce page with your custom action.
3. Once user click the save button, then check the stage in the apex controller, if it matches then create the RFP record and redirect to the new record page.

Below is the sample page.

Apex class:
public with sharing class opptySave {

    private Opportunity oppty;
    
    public opptySave(ApexPages.StandardController controller) {
       oppty = (Opportunity)stdController.getRecord();
    }
    
     public PageReference save() {
        if(oppty.StageName == 'Proposal'){
         RFP__c rfp = new RFP__c();
         //Logic to insert record
         insert rfp;
         PageReference acctPage = new ApexPages.StandardController(rfp).view();
         acctPage.setRedirect(true);
         return acctPage;
         
        }  
        return null;
    }

}

Visualforce:
<apex:page standardController="Opportunity" extensions="opptySave">
  <apex:form >
  <apex:pageBlock >
  <apex:pageBlockButtons >
  <apex:commandButton action="{!save}" value="Save"/>
  </apex:pageBlockButtons>
  <apex:inputField value="{!Opportunity.Name}" label="Opportunity Name"/>
   <apex:inputField value="{!Opportunity.StageName}"/>
  </apex:pageBlock>
  </apex:form>
</apex:page>



 
Gary PayneGary Payne
Thanks for the quick answer.  I attempted to create a new Apex Class with the following code but received "Error: Compile Error: Variable does not exist: stdController at line 6 column 29":

public class OpptyRequestManagement {
    
public with sharing class opptySave {

    private Opportunity oppty;
    
    public opptySave(ApexPages.StandardController controller) {
       oppty = (Opportunity)stdController.getRecord();
    }
    
     public PageReference save() {
        if(oppty.StageName == '02 - Proposal'){
         RFP_Request__c rfp = new RFP_Request__c();
         //Logic to insert record
         insert rfp;
         PageReference acctPage = new ApexPages.StandardController(rfp).view();
         acctPage.setRedirect(true);
         return acctPage;
         
        }  
        return null;
    }

}
}

Any idea on how to fix this code so it does not error.
KaranrajKaranraj
Try the updated code below,
 
public class OpptyRequestManagement {
    
public with sharing class opptySave {

    private Opportunity oppty;
    
    public opptySave(ApexPages.StandardController controller) {
       oppty = (Opportunity)controller.getRecord();
    }
    
     public PageReference save() {
        if(oppty.StageName == '02 - Proposal'){
         RFP_Request__c rfp = new RFP_Request__c();
         //Logic to insert record
         insert rfp;
         PageReference acctPage = new ApexPages.StandardController(rfp).view();
         acctPage.setRedirect(true);
         return acctPage;
         
        }  
        return null;
    }

}
}
 You also need to include logic to insert RFP record in the code