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
etechcareersetechcareers 

How to re-create the Task page in VF with whoid and whatid filled in??? Help please

Hi:

   I want to re-create the Task Page in Visualforce and have the Whoid and what id filled in. Now, I can get this to work if I dont use the VF task page and use the standard task page. But I can not get it to work on the VF Page??/

Basically a user will click new task and it will open up this VF task page and have the whoid and whatid filled in automatically through URL. Do not know how to:

 

public PageReference Monitor(){

    moni = new List<History__c>(
            [SELECT  id,
            Student__c
            FROM History__c 
            where Student__c=:ApexPages.currentPage().getParameters().get('oppIdd')
            AND id=:ApexPages.currentPage().getParameters().get('oppIddc')
            ]);
 
    
   //PageReference newpage = new PageReference('/00T/e?who_id=' + monitorstudent[0].Student__c+ '&what_id=' + monitorstudent[0].Id + '&retURL=%2Fhome%2Fhome.jsp');
    PageReference newpage = new PageReference('/apex/Task?who_id=' + monitorstudent[0].Student__c+ '&what_id=' + monitorstudent[0].Id );

        newpage.setRedirect(true);
        return newpage; 
} 
<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}"/>
                <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>

</apex:page>

 

 

Please help me figure this out. Thanks

ETechCareers

Best Answer chosen by Admin (Salesforce Developers) 
sforce2009sforce2009

Here it goes....

<apex:page standardController="Task" sidebar="false" extensions="extensionsEx">

    <apex:form >
        <apex:pageBlock title="Edit Task" id="thePageBlock" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <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>

</apex:page>


class:

public with sharing class extensionEx{

    Task task = new Task();
    
    public extensionEx(ApexPages.StandardController controller) {
      this.task = (Task)controller.getRecord();
      string strWhatId = System.currentPage().getParameters().get('oppIdd');
      string strOwnerId = System.currentPage().getParameters().get('ownerId');
      Task.WhatId = strWhatId ;
      Task.OwnerId = strOwnerId ;
        
    }

}

 

 

Cheers :)

All Answers

sforce2009sforce2009

Here it goes....

<apex:page standardController="Task" sidebar="false" extensions="extensionsEx">

    <apex:form >
        <apex:pageBlock title="Edit Task" id="thePageBlock" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <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>

</apex:page>


class:

public with sharing class extensionEx{

    Task task = new Task();
    
    public extensionEx(ApexPages.StandardController controller) {
      this.task = (Task)controller.getRecord();
      string strWhatId = System.currentPage().getParameters().get('oppIdd');
      string strOwnerId = System.currentPage().getParameters().get('ownerId');
      Task.WhatId = strWhatId ;
      Task.OwnerId = strOwnerId ;
        
    }

}

 

 

Cheers :)

This was selected as the best answer
etechcareersetechcareers

THANK THANK THANK YOUUUU SOOO MUCH... You are awesome...

sales4cesales4ce

Hi srinivas,

 

For some reason your code does not compile in my org.

What its saying is in the constructor of the controller extension, 

 

Error: Compile Error: Method does not exist or incorrect signature: System.CurrentPage() at line 7 column 26.

 

I replaced the System.Currentpage() with ApexPages.Currentpage() and it got compiled and saved.

 

But when i execute the Vf by passing an Id (Task ID) it raises run time exception and does not populate it with owner id.

 

Am i doing anything wrong. I am trying to learn, but got stuck out here.

 

Any help/idea on this is highly appreciated.

 

Thanks,

Sales4ce

sforce2009sforce2009

is it possible for you to post the code?

sales4cesales4ce

Hi Srinivas,

 

Thanks for your help!.

 

Here is the code:

 

public with sharing class taskExtension 
{
    Task tsk=new Task();
    public taskExtension(ApexPages.StandardController controller) 
    {
        this.tsk=(Task)controller.getRecord();
        String strWhatId=ApexPages.CurrentPage().getParameters().get('id'); // Here if i give System.CurrentPage().getParameters().get('id') gives me compilation error.
        String strOwnerId=ApexPages.CurrentPage().getParameters().get('OwnerId');
        tsk.WhatId=strWhatId;
        tsk.OwnerId=strOwnerId;
    }

}

 

Here is the VF Page:

 

<apex:page standardController="Task" sidebar="true" extensions="taskExtension" >
<apex:form >
<apex:pageblock title="Edit Task" id="taskId" mode="Edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Basic Information" columns="2">
<apex:InputField value="{!Task.OwnerId}"/>
<apex:InputField value="{!Task.Subject}"/>
<apex:InputField value="{!Task.WhoId}"/>
<apex:InputField value="{!Task.WhatId}"/>
</apex:pageBlockSection>

</apex:pageblock>
</apex:form>

</apex:page>

Thanks,

Sales4ce

public with sharing class taskExtension 
{
    Task tsk=new Task();
    public taskExtension(ApexPages.StandardController controller) 
    {
        this.tsk=(Task)controller.getRecord();
        String strWhatId=ApexPages.CurrentPage().getParameters().get('id');
        String strOwnerId=ApexPages.CurrentPage().getParameters().get('OwnerId');
        tsk.WhatId=strWhatId;
        tsk.OwnerId=strOwnerId;
    }

}
ChamCham

were u able to fix the error?

madhavarimallamadhavarimalla

iam trying to create the class for re-create the task page but i got compile error at

"string strWhatId = System.currentPage().getParameters().get('oppIdd');
string strOwnerId = System.currentPage().getParameters().get('ownerId');

....so please send me how to solve that error....

megmooPDXmegmooPDX
Did anyone ever find the solution to the compile error. I, too, get "Method does not exist or incorrect signature: System.currentPage()"
CEPCEP
@megmooPDX you need to use ApexPages instead of System.currentPage()

@Sales4ce has a good example above


ApexPages.CurrentPage().getParameters().get('id')




Chris - ARIChris - ARI
This doesn't work in my Sandbox. Why is that?