This is probably a simple fix, but I'm struggling. I have a VF page that pre-populates Task fields via a controller extension. I want to then give the user the option to create a follow-up task. I want this task to duplicate some of the fields entered by the user in the initial task (e.g., subject, due date + 7 days, etc.). Can anyone help. Thanks
Controller:
public with sharing class RDATasks{
public list<Task> listTask{get;set;}
public list<Task> listTaskFollow{get;set;}
private final Contact con;
public RDATasks(ApexPages.StandardController myController){
listTask = new List<Task>();
listTaskFollow = new List<Task>();
con=(Contact)myController.getRecord();
}
// Adds Task to list
public void RDA()
{
listTask.add(new Task(
WhoId = con.Id,
Status = 'Completed',
ActivityDate = system.TODAY()+7,
OwnerId = UserInfo.getUserId(),
WhatId = con.AccountId,
RDA__c = TRUE)
);
}
// Adds Follow-Up Task to list
public void RDAfollow()
{
listTaskFollow.add(new Task(
WhoId = con.Id,
Status = 'In Progress',
ActivityDate = system.TODAY()+7,
Subject = 'Follow-Up: ',
OwnerId = UserInfo.getUserId(),
WhatId = con.AccountId,
RDA__c = TRUE)
);
}
// Saves list of Tasks added
public PageReference saveTask(){
insert listTask;
insert listTaskFollow;
{
PageReference contactPage = new PageReference('/' + con.Id);
contactPage.setRedirect(true);
return contactPage;
}
}
}
VF Page:
<apex:page standardController="Contact" tabStyle="Contact" sidebar="false" extensions="RDATasks" action="{!RDA}">
<apex:form >
<apex:sectionHeader title="Activities"/>
<apex:repeat value="{!listTask}" var="tsk">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputField value="{!Contact.Account.Name}" label="Related To"/>
<apex:outputField value="{!Contact.Name}" label="Name"/>
<apex:inputField value="{!tsk.Type_of_RDA__c}" style="width:35%"/>
<apex:inputField value="{!tsk.Subject}" style="width:45%"/>
<apex:inputField value="{!tsk.ActivityDate}" style="width:35%"/>
<apex:inputField value="{!tsk.Status}" />
<apex:inputField value="{!tsk.Description}" style="width:100%"/>
<apex:commandButton value="Add Follow Up RDA" action="{!RDAfollow}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:repeat>
<apex:repeat value="{!listTaskFollow}" var="tskF">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputField value="{!Contact.Account.Name}" label="Related To"/>
<apex:outputField value="{!Contact.Name}" label="Name"/>
<apex:inputField value="{!tskF.Type_of_RDA__c}" style="width:35%"/>
<apex:inputField value="{!tskF.Subject}" style="width:45%"/>
<apex:inputField value="{!tskF.ActivityDate}" style="width:35%"/>
<apex:inputField value="{!tskF.Status}" />
<apex:inputField value="{!tskF.Description}" style="width:100%"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:repeat>
<apex:commandButton value="Add Another RDA" action="{!RDA}"/>
<apex:commandButton value="Save RDAs" action="{!saveTask}"/>
</apex:form>
</apex:page>