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
PhanindraPhanindra 

I am trying to navigate to different apex page for that I have written an apex class but it is giving an error. Compile Error: Method does not exist or incorrect signature: [System.PageReference].sendRedirect(Boolean) at line 12 column 1

public class SecondExtension{
public Admin__c adminRecord;
public SecondExtension(ApexPages.StandardController stdCon){
adminRecord=(Admin__c)stdCon.getRecord();
}
public PageReference save(){ 

insert adminRecord;

PageReference pg=new PageReference('apex/PageConfirmation');

pg.sendRedirect(true);
}

public PageReference cancel(){

PageReference pg=new PageReference('/a09/o');
pg.sendRedirect(true);
}
}
 
BALAJI CHBALAJI CH
Hi Michael,

Instead of using sendRedirect() method, you can directly return that page to navigate.
Please find below modified code:
public class SecondExtension{
public Admin__c adminRecord;
public SecondExtension(ApexPages.StandardController stdCon){
   adminRecord=(Admin__c)stdCon.getRecord();
   }

public PageReference save(){ 
   insert adminRecord;
   PageReference pg=new PageReference('apex/PageConfirmation');
   return pg;
   }

public PageReference cancel(){
   
   PageReference pg=new PageReference('/a09/o');
   return pg;
   }
}

Let us know if that helps you.

Best Regards,
BALAJI
 
Ram AgarawalRam Agarawal
Hi
Michael_Kong

Your code do not contain any issue the only thing is that use return type insted of sendRedirect.
PageRefrence class do not contain any member fuction or variable related to send Redirect.
 
Hope its work.
If not then let me know .

Regards 
Ram Agarawal
public class SecondExtension{
public Admin__c adminRecord;
public SecondExtension(ApexPages.StandardController stdCon){
adminRecord=(Admin__c)stdCon.getRecord();
}
public PageReference save(){ 

insert adminRecord;

PageReference pg=new PageReference('apex/PageConfirmation');

Return pg;
}

public PageReference cancel(){

PageReference pg=new PageReference('/a09/o');

Return pg;
}
}

kaustav goswamikaustav goswami
The actual method name is setRedirect not sendRedirect. That is why the compiler is complaining about incorrect method.
Please use the below code snippet.
 
public class SecondExtension{
	public Admin__c adminRecord;
	public SecondExtension(ApexPages.StandardController stdCon){
		adminRecord=(Admin__c)stdCon.getRecord();
	}
	public PageReference save(){ 
		insert adminRecord;
		PageReference pg=new PageReference('apex/PageConfirmation');
		pg.setRedirect(true);
		return pg;
	}

	public PageReference cancel(){
		PageReference pg=new PageReference('/a09/o');
		pg.setRedirect(true);
		return pg;
	}
}

 
PhanindraPhanindra
Thank you guys!! It works fine