function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shobana shobanashobana shobana 

how to display Custom NewTask button in visual force

Hi everyone

I am going to display the Open Tasks for Leads.
I am able to do that, but I would like to show the New Task button(need Standard New Task Functionality), For this, I am doing url hacking, but some how I am missing something.

I am pasting my code below, 

The Intention is to show the Open Tasks, and New Task Button in Visualforce page. Later I will add this VFP to Lead Page layout, so that I can show Open Tasks to particular Lead.

Can any one please help me out?

public class MyOpenTasks {
public List<OpenActivity> open{get;set;}
    public Id leadld;
    public list<lead> c{get;set;}
    public MyOpenTasks (ApexPages.StandardController controller) {
        leadld = ApexPages.CurrentPage().getparameters().get('id');
         c =[SELECT Name, 
                                  (Select Id,Subject,IsTask, WhoId, ActivityDate,
                                    Status, Priority, OwnerId FROM OpenActivities WHERE IsTask=True) 
                            FROM Lead WHERE Id = :leadld];
        if(c.size() > 0){
            open = c[0].OpenActivities;
        // method for command button
    public Pagereference myTasks(){
    PageReference pageRef = new PageReference(' /00T/e?who_id={!ld.Id}&retURL={!ld.Id}');
    return PageRef;
Visualforce Page

<apex:page standardController="Lead" extensions="MyOpenTasks " >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="new task" action="{!myTasks}"/>

                <apex:pageBlockTable value="{!open}" var="each"   >
                <apex:column headerValue="Action">
                <apex:outputlink value="/{!}/e?retURL={!each.WhoId}" target="_top"> Edit </apex:outputlink>
                <apex:column headerValue="Subject" value="{!each.Subject}"/>
                <apex:column headerValue="ActiveDate" value="{!each.ActivityDate}"/>
                <apex:column headerValue="Status" value="{!each.Status}"/>
Thanks in Advance.....
Himanshu ParasharHimanshu Parashar
Hi Shobhana,

Hopefully this code should work for you.
public Pagereference myTasks(){
    PageReference pageRef = new PageReference('/00T/e?who_id=' + ld.Id + '&retURL=' + ld.Id);


    return PageRef;


Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer.