I have a commandLink in a table that calls a method in the apex controller when clicked. I want it to open the pageReference in a new tab.
- The pageReference is meant to open up a Competition-Record page
- I also don't want to hardcode the full URL so I won't have to change it between sandboxes and production. e.g. (https://eu1.salesforce.com/{!CompId})
The issue is that the link doesn't always redirects correctly. Sometimes it will open up the new tab with the new tab being a copy of itself without going to the new pageReference.
- When the redirects fail, neither the debug message is logged or the exception is thrown. (So the method isn't getting called?)
VisualForce Page
<apex:pageBlockTable id="CandList" value="{!lstSelectableCompetitions}" var="comp">
<apex:column headerValue="Name">
<apex:commandLink value="{!comp.competition.Name}" action=" {!doOpenCompetition}" target="_blank">
<apex:param name="compId" value="{!comp.competition.Id}" />
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
Apex Controller (edited)
public PageReference doOpenCompetition(){
String theId = Apexpages.currentPage().getParameters().get('CompId');
System.debug('The Competition Id we want to redirect to is: ' + theId);
if(theId == null || String.isEmpty(theId)){
throw new CompetitionFinderControllerException('ERROR: The Competition Id is null!');
}
PageReference compPage = new PageReference( '/' + theId );
compPage.setRedirect(true);
return compPage;
}