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
sp08830sp08830 

Create task from VF

Task gets created without a subject from this VF page. I think there some simple mistake but am unable to figure out. Can someone help me. 

 

public class test1 {
public task newtask {get; set;}
Public pagereference createTask()  {
NewTask= new Task(ownerid = userinfo.getUserId(),activitydate = Date.today(), Status ='Open', Priority = 'Normal',whatId = 'record id' );
insert newTask;
return new Pagereference('/apex/test1');
    }
}

 

<apex:page controller="test1" >
<apex:form >
<apex:pageMessages />
<apex:outputLabel value="Enter Subject: "/>
<apex:inputField value="{!NewTask.Subject}"/>
<br/>
<apex:commandButton value="Add" action="{!CreateTask}" />
</apex:form>
</apex:page>

 

Sonam_SFDCSonam_SFDC

Hi,

 

By just looking at the piece of code you've provided, I understand that  the createtask() is creating the task but is not initializing any value to the subjecy which looks like the reason the subject is not getting populated..