+ Start a Discussion

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

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

@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.
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];


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');
        insert taskList;

Rahul Sharma