+ Start a Discussion
sk3501.3915272120779841E12sk3501.3915272120779841E12 

How to redirect to lead detail page in salesforce

Hi,
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:
{!REQUIRESCRIPT('/soap/ajax/26.0/connection.js')} 
{!REQUIRESCRIPT('/js/functions.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/jquery-1.8.2.min.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/ui/jquery-ui-1.9.1.custom.min.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/postmessage/jquery.ba-postmessage.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/bbq/jquery.ba-bbq.min.js')} 
requireCssFile('/resource/jQueryForPopup/jQuery/ui/css/ui-lightness/jquery-ui-1.9.1.custom.min.css'); 
function requireCssFile(filename) 

var fileref = document.createElement('link'); 
fileref.setAttribute('rel', 'stylesheet'); 
fileref.setAttribute('type', 'text/css'); 
fileref.setAttribute('href', filename); 
document.getElementsByTagName('head')[0].appendChild(fileref); 


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" />') 
.dialog({ 
autoOpen: false, 
title: 'Sample Popup', 
resizable: true, 
width: 800, 
height: 540, 
autoResize: true, 
modal: true, 
draggable: true 
}); 

j$modalDialog.dialog('open');

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:pageBlockButtons>
            <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:pageBlockSectionItem>
                    <apex:inputField value="{!Task.whoid}"/>
                    <apex:inputField value="{!Task.whatid}"/>
                </apex:pageBlockSection>
            </apex:actionRegion>

        </apex:pageBlock>
    
    </apex:form>
    <script type="text/javascript">
          
        function closeModalDialog() {
            var cross_result = new Object();
            cross_result.action = 'close_modal_dialog';
         
            if (cross_result.action == 'close_modal_dialog') {
            j$modalDialog.dialog('close');
            }
        } 
    </script>
    <!--<script>
        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;
        }
    </script>-->
</apex:page>
sk3501.3915272120779841E12sk3501.3915272120779841E12
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.
sk3501.3915272120779841E12sk3501.3915272120779841E12
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();
        
    }
}