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
Dannielle Givens 4Dannielle Givens 4 

Build a Conference Management App: Batching and Scheduling using APEX

By no means am I a coder/developer but I was excited to have made it this far. I am literally having trouble with this last step and I am not sure how I am to format my code. The goal is to:
  1. Make the class global, implement the Batchable interface, and define the three methods of the interface​
  2. Declare three instance variables to store the query, the email subject, and the email body
  3. Define a constructor implemented
  4. Implement the start() method 
  5. Implement the execute() 
I am not sure if these tasks were to be executed seperately or combined within the code all together. Here is where I'm at:


User-added image


Any help is greatly appreciated!
Best Answer chosen by Dannielle Givens 4
Manuel CasasManuel Casas
Hi Dannielle!

It looks like your last bracket is useless and you are getting an error. Try this code, I passed the challenge whith it:
 
global class SendReminderEmail implements Database.Batchable<sObject> {
    
    global String query;
    global String subject;
    global String body;
    
    global SendReminderEmail(String query, String subject, String body) {
        this.query = query;
        this.subject = subject;
        this.body = body;
  }

     global Database.QueryLocator start(Database.BatchableContext bc) {
      return Database.getQueryLocator(query);
  }


    global void execute(Database.BatchableContext bc, List<Speaker__c> scope) {
        for (Speaker__c speaker : scope) {
            EmailManager.sendMail(speaker.Email__c, this.subject, this.body);
        }
    }


    global void finish(Database.BatchableContext bc) {

    }

}

Let me know if it helps you. Thanks!

Regards.
Manuel Casas.

 

All Answers

Manuel CasasManuel Casas
Hi Dannielle!

It looks like your last bracket is useless and you are getting an error. Try this code, I passed the challenge whith it:
 
global class SendReminderEmail implements Database.Batchable<sObject> {
    
    global String query;
    global String subject;
    global String body;
    
    global SendReminderEmail(String query, String subject, String body) {
        this.query = query;
        this.subject = subject;
        this.body = body;
  }

     global Database.QueryLocator start(Database.BatchableContext bc) {
      return Database.getQueryLocator(query);
  }


    global void execute(Database.BatchableContext bc, List<Speaker__c> scope) {
        for (Speaker__c speaker : scope) {
            EmailManager.sendMail(speaker.Email__c, this.subject, this.body);
        }
    }


    global void finish(Database.BatchableContext bc) {

    }

}

Let me know if it helps you. Thanks!

Regards.
Manuel Casas.

 
This was selected as the best answer
Dannielle Givens 4Dannielle Givens 4
Thank you! And there was so much more wrong with my code than the last bracket. It appear that I took the directions as instructions to replace certain pieces of the code when I was only to add. 

Much appreciation Manuel!
Manuel CasasManuel Casas
You're welcome Dannielle! It was a pleasure to help you!
Menand ModhvadiyaMenand Modhvadiya
how to calling method flow in this Batching and Scheduling in this tutorial.Please explain in step by step .
 
venkat davuluri 31venkat davuluri 31
@manuel Casas:

When i modify the code to what you have mentioned here:

I am getting this error:
Method does not exist or incorrect signature: void sendMail(String, String, String) from the type EmailManager

is it something that i am doing wrong?

Thank you
Venkat

 
Ricki Marking-CamutoRicki Marking-Camuto
Venkat,

I got the same error message, so I replaced Manuel's execute method to the one in the trail and it worked perfectly!
Akhilesh MallickAkhilesh Mallick
Hi Create the code with the following code snippet.. It will work.
global class SendReminderEmail implements Database.Batchable<sObject> {
    
    global String query;
	global String subject;
	global String body;

    global SendReminderEmail(String query, String subject, String body) {
    this.query = query;
    this.subject = subject;
    this.body = body;
}

    
    
    global Database.QueryLocator start(Database.BatchableContext bc) {
    return Database.getQueryLocator(query);
}

    global void execute(Database.BatchableContext bc, List<Speaker__c> scope) {
        String[] addresses = new String[]{},
            	 subjects = new String[]{},
                 messages = new String[]{};
        for (Speaker__c speaker : scope) {
            addresses.add(speaker.Email__c);
            subjects.add(this.subject);
            messages.add(this.body);
        }
        EmailManager.sendMail(addresses, subjects, messages);
    }

    global void finish(Database.BatchableContext bc) {
    }
}