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
mw6mw6 

Call another VF page from another VF page upon click of the button

I have the below VF Page with 10 custom buttons,
<apex:page id="TeacherKPI_VF" controller="TeacherKPI_VF_Controller">
  <apex:form >
  <div style="text-align:center;">
      <h1 style="text-decoration: underline;">TEACHER'S KPI</h1><br/><br/>
      <apex:commandButton value="Lesson Observation" action="{!LessonObservation_VF}"/><br/><br/>
      <apex:commandButton value="File Check" action="{!FileCheck_VF}"/><br/><br/>
      <apex:commandButton value="Request for Corrective Action" action="{!RequestforCorrectiveAction_VF}"/><br/><br/>
      <apex:commandButton value="Withdrawal Trend" action="{!WithdrawalTrend_VF}"/><br/><br/>              
      <apex:commandButton value="Cost Recoverability Index" action="{!CostRecoverabilityIndex_VF}"/><br/><br/>
      <apex:commandButton value="Teacher Parent Dialogue Log" action="{!TeacherParentDialogueLog_VF}"/><br/><br/>
      <apex:commandButton value="Training sessions" action="{!TrainingSessions_VF}"/><br/><br/>
      <apex:commandButton value="Parent's Survey" action="{!ParentSurvey_VF}"/><br/><br/>
      <apex:commandButton value="Student's Survey" action="{!StudentSurvey_VF}"/><br/><br/>
      <apex:commandButton value="Leave / MC" action="{!LeaveMC_VF}"/><br/><br/>
      <apex:commandButton value="Back" action="{!Back}"/>      
  </div>
  </apex:form>
</apex:page>

When any of the button is click, need to open another VF PAGEs for example
<apex:commandButton value="Lesson Observation" action="{!LessonObservation_VF}"/><br/><br/> need to open VF Page LessonObservation_VF, I am not sure on how to do this, please help

The Class is not complete yet
public with sharing class TeacherKPI_VF_Controller {

    public PageReference Back() {
        return null;
    }

    public PageReference LeaveMC_VF() {
        return null;
    }

    public PageReference StudentSurvey_VF() {
        return null;
    }

    public PageReference ParentSurvey_VF() {
        return null;
    }

    public PageReference TrainingSessions_VF() {
        return null;
    }

    public PageReference TeacherParentDialogueLog_VF() {
        return null;
    }


    public PageReference CostRecoverabilityIndex_VF() {
        return null;
    }

    public PageReference WithdrawalTrend_VF() {
        return null;
    }

    public PageReference RequestforCorrectiveAction_VF() {
        return null;
    }

    public PageReference FileCheck_VF() {
        return null;
    }

    public PageReference LessonObservation_VF() {
        return null;
    }

}

 
Best Answer chosen by mw6
Sitarama MurthySitarama Murthy
Hi mw6,

Find the code sample code below to redirect from one vf page to another vf page.

Example :

 public PageReference LeaveMC_VF() {
       PageReference p = new PageReference('/apex/<your_page_name>');
       p.setRedirect(true);
return p;
       
    }

Hope this Helps your problem.

Thanks,
Ram

All Answers

Sitarama MurthySitarama Murthy
Hi mw6,

Find the code sample code below to redirect from one vf page to another vf page.

Example :

 public PageReference LeaveMC_VF() {
       PageReference p = new PageReference('/apex/<your_page_name>');
       p.setRedirect(true);
return p;
       
    }

Hope this Helps your problem.

Thanks,
Ram
This was selected as the best answer
mw6mw6
Thank you Sitarama Murthy and Nagarjun, solved
Heena.Heena.
@SitaramaMurthy, Thank you so much even I was facing the same issue past four days but I got the solution from you!!
Nathalie MelisNathalie Melis

For those that can further help, you can add the record ID and the end of the link to pass the record id to the vf page you are referring to:
         PageReference p = new PageReference('/apex/your_page_name?id=' + opp.id);

"opp" being the object you are calling in your controller (in our case an opportunity):

public with sharing class Yourclass {
    public Opportunity opp {get;set;}   
    Id OpportunityID;
    public Yourclass(ApexPages.StandardController controller) {
        OpportunityID = controller.getId();
        opp = (Opportunity)controller.getRecord();
    }
    public PageReference OnePageFrancais() {
       PageReference p = new PageReference('/apex/your_page_name?id=' + opp.id);
       p.setRedirect(true);
        return p;    
    }
  }

simply buzzes 9simply buzzes 9
Hi mate, thank you so much i was facing the same issue in the past. But i have found the best solution from this thread and from Northell (https://northell.design/blog/how-to-create-a-custom-property-management-system-in-2022/) you can check. if you are still confused then please let me know. i'll happy to serve you. Thanks