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
Ola BamideleOla Bamidele 

PageReference Error - Urgent!

Hi Gurus, 

I have writting an apex code that redirects users to a different language page when they click the link in the Visualforce page. 

However, I am getting an errior on line 10 saying "Missing return statement required return type: System.PageReference" 
public with sharing class CustomerSatTest{
  public String currentRecordId {get;set;}
  public String VFPageName{get;set;}

  public CustomerSatTest (ApexPages.StandardController controller){
    this.currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
  }
  
    
  public PageReference RedirectHelper (String VFPageName) {                   
  		  this.VFPageName = VFPageName;
                  pageRedirect();
  }
 
      public PageReference pageRedirect() {                   
  		   PageReference pageref = new 
                     PageReference('/apex/' + VFPageName + '?Id='+currentRecordId); 
                     pageref.setRedirect(true);
                     return pageref;
  }


 
}

Please if you know how to overcome it then let me know please!
Thanks!
VamsiVamsi
Hi,

Make this method return type as void instead if pagereference.
 
public PageReference RedirectHelper (String VFPageName) {                   
  		  this.VFPageName = VFPageName;
                  pageRedirect();
  }
public void RedirectHelper (String VFPageName) {                   
  		  this.VFPageName = VFPageName;
                  pageRedirect();
  }


 
Ola BamideleOla Bamidele
Hi Vamsi, 

Thanks for the reply. I tried your code but it didnt work unfortunately and I recieved 6 errors XD


Thanks!
VamsiVamsi
Hi, Is there a need to create this ... public PageReference RedirectHelper (String VFPageName) { this.VFPageName = VFPageName; pageRedirect(); } why can't you make use of this directly as it has VFpage name and record id from getter and setter methods .. public PageReference pageRedirect() { PageReference pageref = new PageReference('/apex/' + VFPageName + '?Id='+currentRecordId); pageref.setRedirect(true); return pageref; }
Ola BamideleOla Bamidele
Hi Vamsi, 

I did that previosuly here:
public with sharing class CustomerSatisfactionFR2{
  public String currentRecordId {get;set;}


  public CustomerSatisfactionFR2(ApexPages.StandardController controller){
    this.currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
  }
  
    
  public PageReference UK_Flag () {                   
  		   PageReference pageref = new 
                     PageReference('/apex/CustomerSatisfaction_EN?Id='+currentRecordId); 
                     pageref.setRedirect(true);
                     return pageref;
  }
 
      public PageReference France_Flag () {                   
  		   PageReference pageref = new 
                     PageReference('/apex/CustomerSatisfaction_FR_2?Id='+currentRecordId); 
                     pageref.setRedirect(true);
                     return pageref;
  }


	  public PageReference Dutch_Flag () {                   
  		   PageReference pageref = new 
                     PageReference('/apex/CustomerSatisfaction_NL?Id='+currentRecordId); 
                     pageref.setRedirect(true);
                     return pageref;
  }    

    
		public PageReference Italy_Flag () {                   
  		   PageReference pageref = new 
                     PageReference('/apex/CustomerSatisfaction_IT?Id='+currentRecordId); 
                     pageref.setRedirect(true);
                     return pageref;
  }

    
    
     	  public PageReference Germany_Flag () {                   
  		   PageReference pageref = new 
                     PageReference('/apex/CustomerSatisfaction_DE?Id='+currentRecordId); 
                     pageref.setRedirect(true);
                     return pageref;
  }   
    
       
}

Howeve when I have 4 page references in the apex, only one of the links work. 

DO you know how I can resolve this?

Thanks very much!