+ Start a Discussion

Redirect not working, always redirecting to homepage

I have overridden the New Task buttonto go to a visualforce page which acts as a url creator depending on where the new button was called from.  It builds a the standard new task url but adds a whoId, whatId and retUrl parameter.


My problem is that, i want the user to be redirected to the New Task they just created upon clicking on 'save', however instead the user is taken to the homepage upon saving.  And this is no matter what I put in the retUrl.  If I take out the override and manually add some retUrl values to the default new Task page everything works fine.


What am I doing wrong?



Let me know if you need to see any pieces of code and I will gladly provide. 

Message Edited by astro on 03-08-2010 03:35 AM

As far as my understanding I am sending you the dummy code through which we can redirect anywhere.


PageReference pg= new PageReference('/New Task Created ID');


return pg;


This part of code will be called at the end of the save function means after creation of Task.


If this is what you were using then kindly put the code so that we can check and give the appropriate result.






Hi ckum, Thanks' for replying!  I have tried what you have wrote and no luck.  Could it be because I've overridden the new task button that it ignores my returl parameter for some reason?


Here is my code for the vf page and controller that has overridden the new task button.



<apex:page standardController="Task" extensions="TaskRedirect" action="{!redirect}"></apex:page>



public class TaskRedirect { public final Lead l; public final Contact c; public String whoId; private String campaignId; private String profileName; public TaskRedirect(ApexPages.standardController stdController) { this.profileName = [select u.Profile.Name from User u where u.id = :Userinfo.getUserId()].Profile.Name; System.debug('ProfileName:'+this.profileName); system.debug(stdController); system.debug(ApexPages.currentPage().getParameters().get('who_id')); this.whoId = ApexPages.currentPage().getParameters().get('who_id'); if (this.whoId != null && this.whoId.startsWith('003')) this.c = [Select Id, Name From Contact Where Id = :this.whoId]; else if(this.whoId != null && this.whoId.startsWith('00Q')){ this.l = [Select Id From Lead Where Id = :this.whoId]; } if (this.c != null) //this.campaignId = [Select CampaignId from CampaignMember where ContactId = :this.c.Id limit 1][0].CampaignId; this.campaignId = [select id, CreatedDate, Campaign.Name, Campaign.Id, Campaign.isActive from CampaignMember where Campaign.isActive = true AND ContactId = :this.c.Id ORDER BY CreatedDate desc][0].Campaign.Id; } public PageReference redirect() { PageReference newTaskPage; if(/*this.profileName.equals('Insight Inside Sales') ||*/ this.profileName.equals('System Administrator') && this.c != null){ newTaskPage = new PageReference('/00T/e?nooverride=1&retUrl=%2F'+whoId+'&who_id='+whoId+'&what_id='+campaignId); }else { if(this.whoId != null){ //newTaskPage = new PageReference('/00T/e?nooverride=1&retUrl=%2F'+whoId+'&who_id='+whoId); newTaskPage = new PageReference('/00T/e?nooverride=1&retUrl=%2F00T/o&who_id='+whoId); }else newTaskPage = new PageReference('/00T/e?nooverride=1'); } //newTaskPage.setRedirect(true); return newTaskPage; } }





The redirect method is all that matters.  I have excluded the setRedirect(true) since this is an extension of a standard controller.  However, I should note that i have tried including it as well to no avail.


Not sure what I am doing wrong. 


Thank's again for your help. 




Message Edited by astro on 03-08-2010 06:12 AM
Ron WildRon Wild

Try setting the "nooverride" parameter using the getParameters function...




This should allow you to redirect to the standard page and not be sent to the override.


- R

vivekanand deshmanevivekanand deshmane

Hey Guy's,



Ron Wild wrote:

Try setting the "nooverride" parameter using the getParameters function...




This should allow you to redirect to the standard page and not be sent to the override.


- R

ou required to set below parameters in pagereference.



Then after save action ur page will get redirect to standard object instead of Home page



-vivekaand deshmane