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
SF7SF7 

Mass update tasks with Task list view causing problems with Recurring Tasks

I have a button on task list view which allows users to mass update their tasks.

 

I  have one issue when users are trying to update their tasks using My mass updates tasks functionality they are unable to update their recurring tasks. It throws an exception and when i test it i was able to update some and unable to update some.

 

 

caused by: System.DmlException: Update failed. First exception on row 0 with id 00T3000001rxU18EAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, You cannot update the Status of a recurring task.: [Status]

 

public class TaskListViewController { 
     
    public String objectId {get; set;}
    public Integer numLeft {get; set;}
    public Integer total {get; set;}    
    private Integer startNdx = 0;
    private static Integer PAGESIZE = 8;
    private List<Task> fullTaskList = new List<Task>();
    private List<Task> displayedTaskList = new List<Task>();
    
    
    public TaskListViewController() {

    }
    
    public PageReference refreshPage() {
        return null;
    }
   
    public List<Task> getTasks() {
        String ownerId = UserInfo.getUserId();
        if (fullTaskList.isEmpty())
        {
            fullTaskList = [SELECT Id, WhatId, WhoId, ActivityDate, subject,Activity_Type__c ,status, priority, Description,  ReminderDateTime, IsReminderSet,isClosed 
                            FROM Task 
                            WHERE isClosed = false 
                            AND OwnerId = :ownerId];
            numLeft = fullTaskList.size();
            total = numLeft;
            if(numLeft <> 0)
                this.objectId = ((Task) fullTaskList[0]).id;
         }
        
        displayedTaskList.clear();
        if(numLeft <> 0)
        {
        Integer endNdx = startNdx + PAGESIZE;
        if (endNdx > total)
            endNdx = total;
            
        for (Integer i=startNdx; i<endNdx; i++)
            displayedTaskList.add(fullTaskList.get(i));
         }           
        return displayedTaskList;
    }
 
    private void updateTaskStatus() {
        System.debug('before : ' + fullTaskList);
        Integer i = 0;
        for (i=0; i<fullTaskList.size(); i++) {
            Task t = fullTaskList.get(i);
            if (this.objectId.equals(t.id)) {
                System.debug('updating status of ' + t);                                
                Task tmp = [SELECT Id, WhatId, WhoId, ActivityDate, subject, status, priority, Description, ReminderDateTime, IsReminderSet, isClosed 
                            FROM Task 
                            WHERE id = :t.id];
                fullTaskList.set(i, tmp);
                System.debug('updated to ' + tmp);
                //this.updatedItemStatus = tmp.status;
                break;
            }
        }
        
        System.debug('after : ' + fullTaskList);               
    }
    
    private void nextTask() {
        for (Task t : fullTaskList) {
            if (!t.isClosed) {
                System.debug('found non-closed object with id ' + t.id);
                this.objectId = t.id;
                break;
            }
        }
    }
  

    public void previous() {
        startNdx -= PAGESIZE;
    }
    
    public void next() {
        startNdx += PAGESIZE;
    }    
    
    public void refreshNumbers() {
        updateTaskStatus();
        nextTask();
        this.numLeft = 0;
        for (Task t : fullTaskList) {
            if (!t.isClosed) {
                this.numLeft++;
            }
        }        
      }
    
    public Boolean getHasNext() {
        return total > (startNdx + PAGESIZE);
    }
    
    public Boolean getHasPrevious() {
        return startNdx > 0;
    }    

    public Integer getNum() {
        return total;
    } 
    public PageReference Cancel() {
    PageReference Activitiespage = Page.Activities;
           Activitiespage.setRedirect(true);
           return Activitiespage;
       
    }
    public PageReference save(){       
        for (Task t : fullTaskList) {
           update t;
           
        }
       PageReference Activitiespage = Page.Activities;
           Activitiespage.setRedirect(true);
           return Activitiespage;
    }
    }

 

<apex:page controller="TaskListViewController" standardStylesheets="true" showHeader="true">

    <apex:form id="taskList">
         <script>
            
            function checkIfNeedRefresh() {
                //alert('checking for full refresh');
                var left = document.getElementById('{!$Component.taskList.numberOfItemsLeft}');
                //alert('found items left todo : ' + left.innerHTML);
                var tmp = parseInt(left.innerHTML);
                if (tmp == NaN || tmp == 0) {  
                    parent.refreshPage(); 
                } 
            }

            
        </script>
        <apex:pageBlock id="pageBlock" title="My Tasks List">
        
            <apex:pageBlockButtons >
                    <apex:commandButton action="{!save}" value="Save" id="theButton"/>
                    <apex:commandButton action="{!Cancel}" value="Cancel" id="theButton1"/>
            </apex:pageBlockButtons>
            
            <apex:outputText rendered="{!(tasks.size = 0)}" value="No Open Tasks To display." escape="false"/>
            
            <apex:pageBlockTable value="{!tasks}" var="o" id="table2" rendered="{!IF(tasks.size > 0, true, false)}">
           
<!--
                <apex:column >
                    <apex:commandLink action="{!go}" value="{!o.subject}" reRender="detail">
                         <apex:param value="{!o.id}" name="objectId" assignTo="{!objectId}"></apex:param>
                    </apex:commandLink>
                </apex:column> 
-->
                <apex:column >
                     <apex:facet name="header" ><strong>Subject</strong></apex:facet> 
                     <apex:outputLink title="" value="/{!o.Id}">{!o.subject}</apex:outputLink>
                </apex:column>
<!--
                <apex:column >   
                   <apex:commandLink action="{!go}" rerender="form"> {!o.Subject}
                         <apex:param name="id" value="{!o.Id}"/>
                   </apex:commandLink>
                </apex:column> 
-->
                <apex:column id="status" headerValue="Status"> 
                    <apex:inputField value="{!o.status}"/>
                </apex:column>
<!--            <apex:column id="priority" headerValue="Priority"> 
                    <apex:inputField value="{!o.priority}"/>
                </apex:column> 
-->
                <Apex:column id="type" headervalue="Activity Type">
                  <apex:inputField value="{!o.Activity_Type__c}"/>
                </apex:column>
                
                <apex:column id="ActivityDate" headerValue="Due Date" >
                      <apex:inputField value="{!o.ActivityDate}"/>
                </apex:column>              
                <apex:column id="WhatId" headerValue="Activity Related to" value="{!o.WhatId}"/>
                <apex:column id="WhoId" headerValue="Contact/Lead" value="{!o.WhoId}"/>
<!--            <apex:column id="IsReminderSet" headerValue="Reminder"> 
                      <apex:inputField value="{!o.IsReminderSet}"/>
                </apex:column>
-->                
                <apex:column id="ReminderDateTime" headerValue="Reminder" >
                      <apex:inputField value="{!o.ReminderDateTime}"/>
                </apex:column>
                <apex:column id="Description" headerValue="Comments" >
                      <apex:inputField value="{!o.Description}"/>
                </apex:column>
            
            </apex:pageBlockTable>
        </apex:pageBlock>
        
        <apex:panelGrid columns="2">
            <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous Page</apex:commandlink>
            <apex:commandLink action="{!next}" rendered="{!hasNext}">Next Page</apex:commandlink>
        </apex:panelGrid>
        <apex:outputText id="numberOfItemsLeft" value="{!numLeft}" style="visibility:hidden"/>
        <apex:actionFunction action="{!refreshNumbers}" immediate="true" name="refreshNumbers" rerender="numberOfItemsLeft, detail, table" oncomplete="checkIfNeedRefresh();"/>
    </apex:form>

</apex:page>
sandeep1989sandeep1989

move the activity type to the top of the status and make status to hide when the user selects the activity type recurring. as said the recurring tasks should not be specified a status.