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

update map values

I written one Schedular class : assinging task to system admin
When user will create one client requirement record automatically one task is creating.if he is not completed with in 1 day am assining these task to system admin.

user is created one task he is not completed with in 1 day its assining to system admin.when system admin completed the task and he changed task status to complteds fine it,but in  next day when schedular class run the task status is changing again Not started .

Can any one tell me what is the wrong in my code

Thanks for your help

This is my code

global with sharing class Task_Esc_duedate_users_to_crm_user implements Schedulable
public List<Client_Requirement__c> clientreq=new list<Client_Requirement__c>();

public list<task> listtask=new List<task>();

map<id,task> listtask21=new map<id,task>();

public set<id> CRID=new set<id>();

global void execute(SchedulableContext SC) {

map<Id, User> Id2User = new map<Id, User>([SELECT Id, Name FROM User WHERE Profile.Name IN ('East','Howrah','North and Central','Rajarhat','South I','South II','Newtown')]);
map<Id, User> crmusernewid =new map<Id, User>([SELECT Id, Name FROM User WHERE Asst_crm_user__c=true and Profile.Name IN ('System Admin')]);
system.debug('asst crm user id'+crmusernewid);
clientreq=[select id,name,RecordTypeid,Ownerid  from Client_Requirement__c];
system.debug('List of all  client requirement'+clientreq);
for(Client_Requirement__c cr: clientreq)
CRID.add(;// fetching the list of all client req IDS

listtask=[Select t.CreatedDate, t.Id, t.LastModifiedById, t.LastModifiedDate, t.OwnerId, t.Priority,
t.Status, t.Subject, t.WhatId, t.WhoId,t.ActivityDate,t.Due_Date__c from Task t where Whatid=:CRID and Status='Not Started'  and  ActivityDate=YESTERDAY AND OwnerID IN :ID2User.keyset()];
system.debug('List of tasks that are not closed with in due date of all users '+listtask);

for(task t: listtask)
for(user crm:crmusernewid.values())

t.OwnerId=(;// Assigning the crm owner to the all the tasks


update listtask21.values(); //updating the tasks
system.debug('@@@@ List of tasks that are updated to user crm head '+listtask21);
catch(Exception e){system.debug('@@@@@@@@@@@@@@'+e);}

Hi Venkatesh, 

Your class is not checking if the System Admin has already completed the Task, 

You have to add a For Loop - which condition - checks if the Task is not set to Completed then only Enter the loop which executes the Class. 


Nirmal ChristopherNirmal Christopher
I Agree with Ashish. your code simply updates the list which has Status='Not Started' and if current task  owner is admin you can put these checks in a forloop and stop the update action.