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
D0TD0T 

Reminders not being sent to some users.

User "A" is part of a Team Role when selected a field is prepopulated with User "A" Name. Reminders User "A" based on a Date Forumals which is quartely based.

 

Users were able to recieve them and now it stopped however it is working for only one users. Not sure whats going on. See Code below.

 

global class GenerateQuarterlyRemindersBatchable implements Database.Batchable<SObject>, Database.Stateful {

    global Database.QueryLocator start(Database.BatchableContext bc) {
    
        return Database.getQueryLocator([SELECT Id, Name, Elapsed_Months__c, Next_Effective_Send_Date__c, Account.Final_Interval__c, Account.Analyst__c FROM Opportunity WHERE Requires_Reminder__c = 1]);

    }

    global void execute(Database.BatchableContext bc, List<SObject> batch){
        
        List<Opportunity> opportunitiesThatNeedReminders = new List<Opportunity>();
        
        List<Task> taskRemindersToCreate = new List<Task>();

        for(Opportunity o : (List<Opportunity>) batch) {
            
            System.debug('Old Opportunity: '+o);

            //Update opp details
            Opportunity oTemp = new Opportunity(Id = o.Id);
            
            oTemp.Next_Effective_Send_Date__c = o.Next_Effective_Send_Date__c.addMonths(math.round(o.Account.Final_Interval__c));
            oTemp.Elapsed_Months__c = o.Elapsed_Months__c + o.Account.Final_Interval__c;
            
            System.debug('New Opportunity: '+oTemp);
            
            opportunitiesThatNeedReminders.add(oTemp);
        
            //Create task details
            Task t = new Task();
            t.OwnerId = o.Account.Analyst__c;
            t.Subject = 'Quarterly Report Reminder';
            t.Description = '';
            t.WhatId = o.Id;
            t.ActivityDate = o.Next_Effective_Send_Date__c.addMonths(1);
            
            System.debug('Task: ' + t);
            
            taskRemindersToCreate.add(t);
        
        }
        
        //UPDATE OPPS, INSERT REMINDER TASKS
        if(!opportunitiesThatNeedReminders.isEmpty() && !taskRemindersToCreate.isEmpty()) {
            try {
                database.update(opportunitiesThatNeedReminders);
                database.insert(taskRemindersToCreate);
                
            }
            catch(Exception e) { System.debug('Error: ' + e); }
        }
        
    }
    
    global void finish(Database.BatchableContext bc) {}

 

 

Thanks,

A.Y

Rahul SharmaRahul Sharma

Opportunity records with condition Requires_Reminder__c = 1 should be present for the batch to process.

are you sure, such record exists?