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
FastSnailFastSnail 

Navigation issue - I can not get setRedirect to work in a controller extension

Hello averyone,

I am new to APEX, VF and all. So thanks for your help. What you will find below is very simple but how come the setRedirect() does not work for the view() method? Thanks again.

 

THE PAGE

<apex:page sidebar="false" showheader="false" standardController="Contact" extensions="CCNPositionContExt">
<apex:form >
<apex:commandButton action="{!view}" value="View"  />
<apex:commandButton action="{!cancel}" value="Cancel" />
</apex:form>
</apex:page>

THE CONTROLLER

public with sharing class CCNPositionContExt {
public CCNPositionContExt(ApexPages.StandardController sc) {
  }
public PageReference view(){
  Contact myContact;
  myContact = [SELECT Id FROM Contact WHERE Email =:  'chloe@porsche.com' ];
  PageReference viewPage = new ApexPages.StandardController(myContact).view();
  viewPage.setRedirect(true);
  return viewPage;
}
public PageReference cancel(){
PageReference cancel = page.CCNAbandon;
return cancel;
}  
}

Marty Y. ChangMarty Y. Chang

Hello, FastSnail,

 

Have you tried logging a case with Premier Support?  Your code looks to me like it should work the way you expect.

Starz26Starz26

Copied your code directly, changed the email in the SOQL and the Page Name for cancel but they both worked fine here.

 

What exactly happens when you click the button?

 

 

FastSnailFastSnail

Hello gentlemen,

Thanks for looking in this issue. I was maybe not clear on explaining my problem. The view button takes me indeed to the correct contact detail page but the URL Link does not navigate as I beleive it should be (which is the point of setRedirect right?) How can I get the contact URl view link (https://na10.salesforce.com/003F000000xPDxo)? It stays stuck at https://c.na10.visual.force.com/apex/CCNLogin  See picture below. Furthemore, why is the https no more valid now? Thanks again.

SetRedirect issue.