+ Start a Discussion
EchoMarcEchoMarc 

Standardcontroller.edit() PageReference return causing page load to loop to same page

Hi there,

 

I overrode the Task edit button with the following VF page.

 

Visualforce page code:

 

<apex:page standardController="Task" extensions="TaskEditOverride" action="{!getEditPage}" >
    <apex:form >
        <apex:outputText value="{!Task.Id} {!Task.MPDN_ID__c}" rendered="false"/>
    </apex:form>
</apex:page>

 

Controller Extension:

 

public class TaskEditOverride {
   
    ApexPages.Standardcontroller controller {get; set;}
    Task task {get; set;}
   
   
    /*Constructor*/
    public TaskEditOverride(ApexPages.Standardcontroller controller){
        this.controller = controller;
        this.task = (Task)controller.getRecord();
       
    }
   
    public PageReference getEditPage(){
        PageReference taskEdit = controller.edit(); 

        if(task.MPDN_ID__c == null){
            return taskEdit;

        } else {
            //This page exists
            return Page.Meeting;
        }


    }

}

 

 

Whenever I hit the edit button, it tries to load a big long URL about 20 times (looks like it's caught in some loop) and then finally settles on https://na1.salesforce.com/{!Task.Id}/e.  On that page, when I press Save or Edit, it reloads the https://na1.salesforce.com/{!Task.Id}/e page (so I'm caught in another loop).

 

I get the same behavior if I try to return new PageReference('/' + this.task.Id + '/e?retURL=%2F'+this.task.Id). 

 

Would anyone be so kind as to tell me why this seems to be happening? 

 

Much appreciated,

 

Marc

 

 

mtbclimbermtbclimber

Because that's what your logic is telling it to do.

 

If I'm following you correctly instead of sending the user to the edit action on the standardcontroller for task when task.MPDN_ID__c is null, why don't you just return null which should display your page which, apparently is the override for task edit.

 

e.g:

 

public PageReference getEditPage(){ if(task.MPDN_ID__c == null){ return null; } else { //This page exists return Page.Meeting; } }

 

 

 

EchoMarcEchoMarc

Thanks for taking the time to reply.

 

Unfortunately, returning null just returns a blank page.  What I want to do in the case where MPDN_Id__c == null is return the standard edit page for a Task.  That's why I thought to use the edit() function of the StandardController class because it "Returns the PageReference of the standard edit page."  

 

Any ideas how to get it to return the standard edit page properly?