+ Start a Discussion

How to redirect to lead detail page in salesforce

I am using a custom button on lead detail page i.e. pop up and creating a pop window using javascript. That pop window has visualforce page to create new task. When i save the task it redirects me to task detail page. while i want when i click on save it redirect me to lead detail page and show the new task in open activity. please help me how do i redirect to lead detail page.

javascript code i am using on the custom button is given below:
function requireCssFile(filename) 

var fileref = document.createElement('link'); 
fileref.setAttribute('rel', 'stylesheet'); 
fileref.setAttribute('type', 'text/css'); 
fileref.setAttribute('href', filename); 

var j$ = jQuery.noConflict(); 
var iframe_url = '{!URLFOR("/apex/vfPopup")}'; 
var child_domain = iframe_url.substring(0, iframe_url.indexOf('/', 9)); 
var parent_domain = window.location.protocol + '//' + window.location.host; 
var j$modalDialog = j$('<div id="opppopup"></div>') 
.html('<iframe id="iframeContentId" src="' + iframe_url + '" frameborder="0" height="100%" width="100%" marginheight="0" marginwidth="0" scrolling="no" />') 
autoOpen: false, 
title: 'Sample Popup', 
resizable: true, 
width: 800, 
height: 540, 
autoResize: true, 
modal: true, 
draggable: true 


Visualforce code is given below:

<apex:page standardController="Task" sidebar="false">
    <apex:form >
        <apex:pageBlock title="Edit Task" id="thePageBlock" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" onComplete="closeModalDialog();"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>              
            <apex:actionRegion >
                <apex:pageBlockSection title="Basic Information" columns="1">
                <apex:inputField value="{!Task.Ownerid}"/>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Subject"/>
                            <apex:inputField value="{!Task.Subject}"/>
                    <apex:inputField value="{!Task.whoid}"/>
                    <apex:inputField value="{!Task.whatid}"/>

    <script type="text/javascript">
        function closeModalDialog() {
            var cross_result = new Object();
            cross_result.action = 'close_modal_dialog';
            if (cross_result.action == 'close_modal_dialog') {
        var returnURL;

        window.onload =  function(){
        returnURL = gup('retURL');
        //alert('Set retURL = ' + returnURL);
        function gup( name ){  //this function just grabs HTTP params by name
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
        var regexS = "[\\?&]"+name+"=([^&#]*)"; 
        var regex = new RegExp( regexS ); 
        var results = regex.exec( window.location.href );
         if( results == null )    return ""; 
        else    return results[1];}
        function redirectBack(){
        //alert('Sending you back to ' + returnURL);
        window.location.href = '/' + returnURL;
Hello, If anyone no the solution then please reply as soon as possible please.
Vijay AdusumilliVijay Adusumilli
When you use standard controller (as you are doing here) and use actions from that controller, the default screen returned is the detail page of that object. So, if you do not want to that, create an extension. In the extension, implement the action. If you want, you can call the action implemented in the standard controller but catch the returned page (which would be the detailed page of the object) and return null from your custom action method in your extension.
Hi Vijay,

Please tell me how to implement this.
Vijay AdusumilliVijay Adusumilli
Try this:

Change the first line in Visual page to:
<apex:page standardController="Task" extensions="TaskCustomSave" sidebar="false">

Here is the code for TaskCustomSave:

public class TaskCustomSave {
    private final Task task;
    ApexPages.StandardController TaskStdController;
    public TaskCustomSave(ApexPages.StandardController stdController) {
        this.TaskStdController = stdController;
        this.task = (Task)stdController.getRecord();
    public void save() {
        System.PageReference pageRef = TaskStdController.save();