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
megmooPDXmegmooPDX 

custom VisualForce page for task

I would like to create a custom visualforce page for creating a new task. Scenario: user clicks a button on the Activities related list on the parent object. That button launches a VF force page with both standard fields and custom fields for the Task. User populates those fields, then clicks Save. 

I've tried all sorts of things hobbled together from research online, but so far, no luck. 

(I'm a newbie at VF and apex)

Here's my current VF Page code:

<apex:page standardController="Task" extensions="extension_task">
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageblockButtons >
<apex:commandButton value="Save" action="{!save}" />
</apex:pageblockButtons>
        <apex:pageBlockSection title="Quick Edits" columns="1">
            <apex:inputField value="{!Task.Whatid}"/>
            <apex:inputField value="{!Task.Subject}"/>
            <apex:inputField value="{!Task.Representative__c}"/>
            <apex:inputField value="{!Task.Category__c}"/>
            <apex:inputField value="{!Task.Comments__c}" style="width:400px; height:200px"/>
            <apex:inputField value="{!Task.Perceived_Call_Value__c}"/>
            <apex:inputField value="{!Task.Referred_To__c}"/>
            <apex:inputField value="{!Task.Interaction__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>


Here's the apex class extension:

public class extension_task{

    Task task = new Task();
   
    public extension_task(ApexPages.StandardController controller) {
      this.task = (Task)controller.getRecord();  
    }

}

**************************
I think a problem is that Task cannot be used as a StandardController. I tried setting the StandardController="ACA_Member__c", but that gives me an error (Error: Unknown property 'ACA_Member__cStandardController.Task'). It seems I should be able to use my custom object with standardController based on this page (http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_std_associate.htm).

Thanks any advance for any help!
Best Answer chosen by megmooPDX
Phillip SouthernPhillip Southern
You can still pass parameters to a VF page, you would need to actually use an extension now...and in the extension you can pull the parameters from the URL and do assignments from there...so for example if you passed something like:

https://www.salesforce.com/apex/VFPage?subject=test

Then in your apex extension right under where you did the controller.getrecord() you could do

task.subject = System.currentPageReference().getParameters().get('subject');


Here's another example from the dev boards: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000997LIAQ

All Answers

Phillip SouthernPhillip Southern
Hi, so a couple responses on this:

1.) Sounds like you could use standard page layouts to accomplish this...you might not even need VF/Apex.

2.) Based on requirement (quick create of a task) and the code you've provided...looks like you dont even need the extension and Apex class.  The standard controller can handle everything by itself.  So you dont need to the apex class and you can remove the extension attribute from the page on line 1 of the VF page.  So just do: <apex:page standardController="Task">
megmooPDXmegmooPDX
1. Yes, I can. I'm doing a VF page because my users want the comment field to be larger. I researched and found that there isn't a way to make the comment field bigger by default. The user can click the bottom right corner of the box and drag it bigger, but I've found nothing to indicate that making the comment box bigger by default is possible. So I moved onto a VF page.

2. I've tried to just use StandardController="Task". What happends then is strange. It will appear to save the task record and shows me the detail record of the items I just entered (see the first screen shot below). The task has the correct Related To person entered, but when I click on the link of that Related To person, the task does not appear in the activity history. It is like it is not being associated with the Related To item despite the detail record showing it is.

User-added image
User-added image

That's why I thought something must be wrong with the way I was using the StandardController.
megmooPDXmegmooPDX
Update: the good news is that I figured out why the task wasn't appearing in the Activity History list. It's status was set to "Not Started." I didn't realize that the Activity History doesn't show ALL tasks, but rather just those that are Completed. In hindsight, duh.

The bad news is that the fields on my VF task page are not default populating via my URL hack to the VF page as they were to a the standard task page.

After doing a lot of research, it seems that I can't pass parameters via a URL to a VisualForce page using the same URL Hack method. Does anyone have ideas on how I can pre-populated some of the fields on my VF page for Task? My users click an "Engaged" button on the task related list, then are taken to the VF page. I want that VF page to pre-populate some fields. Ideas?
Phillip SouthernPhillip Southern
You can still pass parameters to a VF page, you would need to actually use an extension now...and in the extension you can pull the parameters from the URL and do assignments from there...so for example if you passed something like:

https://www.salesforce.com/apex/VFPage?subject=test

Then in your apex extension right under where you did the controller.getrecord() you could do

task.subject = System.currentPageReference().getParameters().get('subject');


Here's another example from the dev boards: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000997LIAQ
This was selected as the best answer
nagendra kumar 21nagendra kumar 21
Hi Meg,

I new to SF Coding, and i got the same issues in my work, users need few comments boxs to be larger, so my manager suggested me to create a new custom VF page for NEW TASK and NEW EVENT,  but i dont know how to wtire a code for it. Could you please assest me on how can i do it ? Any suggestions is appriciated. Thanks, Nagendra