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
aMackDawg121930aMackDawg121930 

Trailhead's Apex Scheduler: TaskUtils not recognized?

I created a new class 'RemindOpptyOwners' per the Trailhead tutorial on Apex Scheduler, but the code will not compile, because
 
'Variable does not exist: TaskUtils'
Here is the code I have:
 
global class RemindOpptyOwners implements Schedulable {

    global void execute(SchedulableContext ctx) {

        List<Opportunity> opptys = [SELECT Id, Name, OwnerId, CloseDate
            FROM Opportunity
            WHERE IsClosed = False AND
            CloseDate < TODAY];
        // Create a task for each opportunity in the list
        TaskUtils.remindOwners(opptys);
    }
}

I transcribed this code at first, but then copied and pasted directly into the Dev console and got the same error. Why is TaskUtils not being recognized?

API Version: 37.0
 
Nayana KNayana K
code is trying to find TaskUtils apex class with remindOwners static method.

public class TaskUtils
{

public static void remindOwners(List<Opportunity> lstOpp)
{
// code here for creating task to remind opportunity owner
}

 
aMackDawg121930aMackDawg121930
@Nayana, thank you! I guess my confusion was stemming more from why Salesforce was referencing foreign classes in a tutorial and could not have provided examples using default classes.
Rahul.SharmaRahul.Sharma
Hi @aMackDawg121930
Use this code :

global class RemindOpptyOwners implements Schedulable{
    global void execute(SchedulableContext cntxt){
        List<Opportunity> oppList = [SELECT ID, Name, OwnerId, CloseDate FROM Opportunity WHERE 
                                     IsClosed= FALSE AND CloseDate<Today];
        RemindOpportunityOwners.createTaskforOpp(oppList);
    }

}

Class for creating task is:

public with sharing class RemindOpportunityOwners {
public static void createTaskforOpp(List<Opportunity> oppList) {

    List<Task> taskList = new List<Task>();
    For(Opportunity opp : oppList) {
      Task newTask = new Task(
           WhatId = opp.Id,
           OwnerId = opp.OwnerId,
           ActivityDate = Date.today(),
          Subject = 'Update Opportunity',
           Description = 'Kindly close the ticket by the end of the day');
        taskList.add(newTask);
        }
        insert taskList;
    }
}

Regards,
Rahul Sharma