We help IT Professionals succeed at work.

reminder emails

sullisnyc44
sullisnyc44 asked
on
I like to write an apex class that sends a reminder email when a particular field is = today.

when I try to add this code I get errors. not sure why

Error: Compile Error: expecting right curly bracket, found 'EOF' at line 0 column -1

@IsTest
public class myRenewalDateNotify
{
 public static void sendRenewalNotify()
 {
  List<Account> aa=[SELECT Id,Name,Renewal_Date__c from Account WHERE Renewal_Date__c = Today];
    if (!aa.IsEmpty())
    {
    // send email notification    
        
        integer i = [Select COUNT() from Account where Renewal_Date__c = Today];
        
        system.debug=(i +' accounts are set for renewal today');    
       //String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + acct.Id;        
       //String[] toaddress = new String[]{};toaddress.add(emailaddress[i]);
       //Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       //mail.setToAddresses(toaddress);mail.setsubject(subject);
       
   // }
    }
  }

Open in new window

Comment
Watch Question

IT-specialist
Commented:
You have opening brackets at line 3,5,8 and closing on 20,21
Does uncommenting line 19 help ?

Author

Commented:
Yes. it did.

however now I get another error when I uncomment the debug line:
Error: Compile Error: Variable does not exist: system.debug at line 13 column 8


@IsTest
public class myRenewalDateNotify{

  public static void sendRenewalNotify(string message){

      
    List<Account> accts=[SELECT Id,Name,Renewal_Date__c from Account WHERE Renewal_Date__c = Today];
  if (!accts.IsEmpty()){
        // send email notification    
        
        integer i = [Select COUNT() from Account where Renewal_Date__c = Today];
        
       system.debug=(i +' accounts are set for renewal today');    
    //String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + acct.Id;        
       //String[] toaddress = new String[]{};toaddress.add(emailaddress[i]);
       //Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       //mail.setToAddresses(toaddress);mail.setsubject(subject);
       
    }
  }
 }

Open in new window

Author

Commented:
I think this is what I would like to do.

i would like to query Accounts and see what is due for renewal today.

I would like to send one email message to myself and someone else that contains a list of those accounts with links to those accounts.

how do I build the body of the message?

@IsTest
public class myRenewalDateNotify{

  public static void sendRenewalNotify(string message){

      
    List<Account> accts=[SELECT Id,Name,Renewal_Date__c from Account WHERE Renewal_Date__c = Today];
  if (!accts.IsEmpty()){
        // send email notification    
        
       integer i = [Select COUNT() from Account where Renewal_Date__c = Today];
       system.debug=(i +' accounts are set for renewal today');    

        //String[] toaddress = new String[]{};toaddress.add(emailaddress[i]);    
        //Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();    
        //mail.setToAddresses(toaddress);mail.setsubject(subject);
       
         // loop through and build email body       
        for(Account a : accts){
        //String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + acct.Id;        

         }
        }
       }
     }

Open in new window