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
$force$force 

how to redirect to the detail page

Hi guys,

 

please help me to redirect to the detail page on click a button.

 

Public Class Comments{
public Comments__c Com{get; set;}


id str;
id str1;

public Comments(ApexPages.StandardController controller) {
Com=(Comments__c)controller.getRecord();
str=Apexpages.currentpage().getparameters().get('id');
System.debug('======================================>'+str);
}
public Comments(){
List<Comments__c> c=[select id, Contact__r.Id ,Finance__r.id, Application__r.Id from comments__c where id=:str];
if(c!=null){
for(Integer i=0;i<=c.size();i++){
str1=c[i].Contact__r.Id;
system.Debug('--->'+str1);
}
}

}

public PageReference lead() {
PageReference pageRef = new PageReference('/00Q/o');
return pageRef;
}
public PageReference Applicant() {
PageReference pageRef = new PageReference('/'+c.Contact__r.id);
return pageRef;
}
public PageReference Application() {
PageReference pageRef = new PageReference('/'+c.Application__r.id);
return pageRef;
}
public PageReference Finance() {
PageReference pageRef = new PageReference('/'c.Finance__r.id);
return pageRef;
}
}

 

i am calling the page reference on a button click.when i click that button then they should redirect to that record detail page.

 

Thanks

$F

bob_buzzardbob_buzzard

I don't thnk you can use 'c' as that's a local variable to the constructor.  You'll need to store the value in the controller somewhere.  Something like:

 

Public Class Comments{
public Comments__c Com{get; set;}
private Comments__c comWithRelated;

id str;
id str1;

public Comments(ApexPages.StandardController controller) {
Com=(Comments__c)controller.getRecord();
str=Apexpages.currentpage().getparameters().get('id');
System.debug('======================================>'+str);
}
public Comments(){
List<Comments__c> c=[select id, Contact__r.Id ,Finance__r.id, Application__r.Id from comments__c where id=:str];
if(!cisEmpty()){
for(Integer i=0;i<=c.size();i++){
str1=c[i].Contact__r.Id;
system.Debug('--->'+str1);
comWithRelated=c[0];
}
}

}

public PageReference lead() {
PageReference pageRef = new PageReference('/00Q/o');
return pageRef;
}
public PageReference Applicant() {
PageReference pageRef = new PageReference('/'+comWithRelated.Contact__r.id);
return pageRef;
}
public PageReference Application() {
PageReference pageRef = new PageReference('/'+comWithRelated..Application__r.id);
return pageRef;
}
public PageReference Finance() {
PageReference pageRef = new PageReference('/'comWithRelated.Finance__r.id);
return pageRef;
}
}

 Ideally these methods would check whether comWithRelated is null first, but I've left that as an exercise for the avid student.