• Aniketh Kattimani
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi Guys,

I am new to developing and needed some assistance in understand this error message which i get when i execute the below mentioned batch to send email notification on daily basis if checkbox is false (Which includes some more conditions :

Requirement 1 : Build a nightly job to send an Email to the Primary Contact Email address on the opportunity if any of the following checkboxes are not checked
Section 1  
Section 2
Section 3
Section 4
Section 5
Requirement 2 : Section 5 is not required for opportunities having a stored date prior to 10/1/2013
Requirement 3 : 
Emails are triggered based on the following:
Enrollment date is < current date && Storage date = Null && DueDate = CurrentDate+14
OR
Enrollment date != Null && Storage date = CurrentDate + 7
global class OpportunityEnrollmentAlert implements Database.Batchable<sObject>,Database.Stateful{
    
APEX Code :
global List <String> emailAdd = new List<String>();
    global final Date DueCheck = Date.newInstance(2013, 10, 1);
    List<Messaging.SingleEmailMessage> mails = new  List<Messaging.SingleEmailMessage>();
    global Database.Querylocator start(Database.BatchableContext BC){
        
        String query = 'SELECT Id, Name, Primary_Contact__c, Primary_Email__c, Enrollment_Date__c, Storage_Date__c from Opportunity where (Section_1_Received__c = FALSE OR Section_2_Received__c = FALSE OR Section_3_Received__c = FALSE OR Section_4_Received__c = FALSE OR Section_5_Received__c = FALSE && objScope.Storage_Date__c > DueCheck)';
        system.debug('query==========>>>>>>>'+query);
        return Database.getQueryLocator(query);
        
    }
    
    global void execute(Database.BatchableContext BC, List<Opportunity> scope){
        system.debug('Inside execute method');
        system.debug('scope=====>>>>>'+scope);
        set<id> oppIdList = new set<id>();
        
        for (Opportunity objScope: scope){
            
            if (objScope.Enrollment_Date__c < Date.Today() && objScope.Storage_Date__c == NULL && objScope.Due_Date__c == Date.Today().addDays(14)){
                System.debug('_------------------Test');
            }
            else if(objScope.Enrollment_Date__c != NULL && objScope.Storage_Date__c == Date.Today().addDays(7)){
            }
            oppIdList.add(objscope.id);
        }
        
        if (oppIdList!= null && oppIdList.size()>0){
            
        }
        
        if(scope!=null || !scope.isEmpty()){
            for(Opportunity opp:scope){
                system.debug('primary contact email'+opp.Primary_Email__c);
                
                // Step 1: Create a new Email
                Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                
                // Step 2: Set list of people who should get the email
                emailAdd.add(opp.Primary_Email__c);
                message.setToAddresses(emailAdd);
                
                // Step 4. Set email contents - you can use variables!
              
                Id etId = [select id, Name from EmailTemplate where developername='Missing_Enrollment_Forms'].id;
                message.setTargetObjectId(opp.Primary_Contact__c);
                message.setTemplateId(etId);
                mails.add(message);    
            }
        }
        // Step 6: Send all emails in the master list
        Messaging.sendEmail(mails);
    }
    global void finish(Database.BatchableContext BC){    
    }
}
Error : 
User-added image

Appreciate all your help.
Hi Guys,

I am new to developing and needed some assistance in understand this error message which i get when i execute the below mentioned batch to send email notification on daily basis if checkbox is false (Which includes some more conditions :

Requirement 1 : Build a nightly job to send an Email to the Primary Contact Email address on the opportunity if any of the following checkboxes are not checked
Section 1  
Section 2
Section 3
Section 4
Section 5
Requirement 2 : Section 5 is not required for opportunities having a stored date prior to 10/1/2013
Requirement 3 : 
Emails are triggered based on the following:
Enrollment date is < current date && Storage date = Null && DueDate = CurrentDate+14
OR
Enrollment date != Null && Storage date = CurrentDate + 7
global class OpportunityEnrollmentAlert implements Database.Batchable<sObject>,Database.Stateful{
    
APEX Code :
global List <String> emailAdd = new List<String>();
    global final Date DueCheck = Date.newInstance(2013, 10, 1);
    List<Messaging.SingleEmailMessage> mails = new  List<Messaging.SingleEmailMessage>();
    global Database.Querylocator start(Database.BatchableContext BC){
        
        String query = 'SELECT Id, Name, Primary_Contact__c, Primary_Email__c, Enrollment_Date__c, Storage_Date__c from Opportunity where (Section_1_Received__c = FALSE OR Section_2_Received__c = FALSE OR Section_3_Received__c = FALSE OR Section_4_Received__c = FALSE OR Section_5_Received__c = FALSE && objScope.Storage_Date__c > DueCheck)';
        system.debug('query==========>>>>>>>'+query);
        return Database.getQueryLocator(query);
        
    }
    
    global void execute(Database.BatchableContext BC, List<Opportunity> scope){
        system.debug('Inside execute method');
        system.debug('scope=====>>>>>'+scope);
        set<id> oppIdList = new set<id>();
        
        for (Opportunity objScope: scope){
            
            if (objScope.Enrollment_Date__c < Date.Today() && objScope.Storage_Date__c == NULL && objScope.Due_Date__c == Date.Today().addDays(14)){
                System.debug('_------------------Test');
            }
            else if(objScope.Enrollment_Date__c != NULL && objScope.Storage_Date__c == Date.Today().addDays(7)){
            }
            oppIdList.add(objscope.id);
        }
        
        if (oppIdList!= null && oppIdList.size()>0){
            
        }
        
        if(scope!=null || !scope.isEmpty()){
            for(Opportunity opp:scope){
                system.debug('primary contact email'+opp.Primary_Email__c);
                
                // Step 1: Create a new Email
                Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                
                // Step 2: Set list of people who should get the email
                emailAdd.add(opp.Primary_Email__c);
                message.setToAddresses(emailAdd);
                
                // Step 4. Set email contents - you can use variables!
              
                Id etId = [select id, Name from EmailTemplate where developername='Missing_Enrollment_Forms'].id;
                message.setTargetObjectId(opp.Primary_Contact__c);
                message.setTemplateId(etId);
                mails.add(message);    
            }
        }
        // Step 6: Send all emails in the master list
        Messaging.sendEmail(mails);
    }
    global void finish(Database.BatchableContext BC){    
    }
}
Error : 
User-added image

Appreciate all your help.