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
Lakshmi SLakshmi S 

How to redirect the page to custom object after clicking on Cancel button?

Hi Team,

How to redirect the custom vf page to custom object after clicking on Cancel button?
public with sharing class HighRiskSuccessFactorsCls {
    
    public High_Risk_Success_Factors__c hrsf {get;set;}
    ApexPages.StandardController con;
    public HighRiskSuccessFactorsCls(ApexPages.StandardController sc){
        con=sc;
    }
    
    public PageReference saveNew()
     { 
         PageReference pr; 
         try{ con.save();
         Schema.DescribeSObjectResult describeResult = con.getRecord().getSObjectType().getDescribe();
         pr = new PageReference('/' + describeResult.getKeyPrefix() + '/e');
         pr.setRedirect(true);
         return pr;
         }catch(Exception e){ 
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
         return null; }
     
     }
    Public PageReference doCancel(){
        PageReference pageRef = new PageReference('/apex/High_Risk_Success_Factors__c?id='+hrsf.id+'&Sfdc.override=1');
    	pageRef.getParameters().put('tab','High Risk Success Factors');
    	return pageRef;	
    }

}
Please let me know how can i redirect to custom object tab.

Thanks.
Lakshmi
 
Best Answer chosen by Lakshmi S
<Saket><Saket>
Hi Lakshmi
Return this Page Reference in your cancel controller method
 
PageReference pg = new PageReference('/'+Schema.SObjectType.{Custom Object Api Name}.getKeyPrefix()+'/o');

This will redirect to the object tab.

Thanks
Saket Sharma

All Answers

Sampath SuranjiSampath Suranji
Hi Lakshmi,

Try like this,
PageReference pr = new PageReference('/'+Schema.SObjectType.YOUR_CUSTOMOBJECT_APINAME.getKeyPrefix());
return pr;
Best Regards
Sampath
 
<Saket><Saket>
Hi Lakshmi
Return this Page Reference in your cancel controller method
 
PageReference pg = new PageReference('/'+Schema.SObjectType.{Custom Object Api Name}.getKeyPrefix()+'/o');

This will redirect to the object tab.

Thanks
Saket Sharma
This was selected as the best answer
Lakshmi SLakshmi S
Hi Saket,

Thnaks for your reply.

How to override the standard clone functionality?

Thanks.
Lakshmi.
 
<Saket><Saket>
Hi Lakshmi,

To override the standard clone functionality you have to go the object page and go to Buttons Links and Actions underneath it you will find a row for clone as I attached the screenshot below please have a look, click on edit in clone, override it with your vf page.  
Click Edit on the marked row for clone

if it dosen't solve your problem then please let me know.

Thanks 
Saket Sharma