0

I have a VF page with a custom Extension controller that creates a task or series of tasks on a button click from the Contact page. Users have the ability to create an initial task then a follow up or another un-related task. The issue I am running into is when a user creates an initial task and a follow-up and then creates another un-related task, the follow-up task previously created gets cloned. I want the un-related task to not have a follow-up task until/if the user decides they want one. Any ideas on how to handle?

Controller:

public with sharing class RDATasks{

    public list<Task> listTask{get;set;}
    public list<Task> listTaskFollow{get;set;}
    public integer n;

    Set<Task>Tasks = new Set<Task>();
    Set<Task>FollowTasks = new Set<Task>();

    private final Contact con;
    public RDATasks(ApexPages.StandardController myController){
        listTask = new List<Task>();
        listTaskFollow = new List<Task>();
        con=(Contact)myController.getRecord();
    }

//  Adds RDA Task to list
    public void RDA()
    {
        listTask.add(new Task(
           WhoId = con.Id,
           Status = 'Completed',
           ActivityDate = system.TODAY(),
           Subject = '',
           Description = '',
           OwnerId = UserInfo.getUserId(),
           WhatId = con.AccountId,
           RDA__c = TRUE,
           FollowUp__c = FALSE)
           );
    }

//  Adds RDA Follow-Up Task to list
    public void RDAfollow()
    {
        n=listTask.size() - 1;
        listTask[n].FollowUp__c = FALSE;
        listTaskFollow.add(new Task(
           WhoId = con.Id,
           Status = 'In Progress',
           ActivityDate = system.TODAY()+7,
           Subject = 'Follow-Up: '+listTask[n].Subject,
           OwnerId = UserInfo.getUserId(),
           WhatId = con.AccountId,
           RDA__c = TRUE,
           FollowUp__c = TRUE)
           );
    }

//  Saves list of RDA Tasks added
    public PageReference saveTask(){
        insert listTask;
        insert listTaskFollow;

        if(!listTaskFollow.isEmpty()){
            Tasks.addAll(listTask);
            FollowTasks.addAll(listTaskFollow);
        if(!Tasks.containsAll(FollowTasks)){
            integer last = listTaskFollow.size();
            listTask.add(listTaskFollow[last]);
        }
        }
        RDAfollow();
            {
            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="Revenue Driving Activities"/>
<apex:repeat value="{!listTask}" var="tsk">
    <apex:pageBlock >
        <apex:pageBlockSection title="Main RDA">
            <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.Type_Detail__c}" style="width:35%"/>
            <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:repeat value="{!listTaskFollow}" var="tskF">
        <apex:pageBlockSection title="Follow-Up RDA">
            <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.Type_Detail__c}" style="width:35%"/>
            <apex:inputField value="{!tskF.ActivityDate}" style="width:35%"/>
            <apex:inputField value="{!tskF.Status}" />
            <apex:inputField value="{!tskF.Description}" style="width:100%"/>
        </apex:pageBlockSection>
</apex:repeat>

    </apex:pageBlock>
</apex:repeat>

    <apex:commandButton value="Add Another RDA" action="{!RDA}"/>
    <apex:commandButton value="Remove Last RDA" action="{!removeRDA}"/>
    <apex:commandButton value="Save RDAs" action="{!saveTask}"/>
</apex:form>

</apex:page>
  • You have given full functional requirements in this question. you can break it in a simpler way so that members could willing to answer this – Santanu Boral Jan 24 '17 at 16:06
  • Thanks. I simplified my request. I was just trying to provide as much detail as possible. – John Neilan Jan 24 '17 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.