You need to sign in to do that
Don't have an account?
Error: Compile Error: expecting a right parentheses for Apex Scheduler
I am trying to implement a schedule class in Apex. I got my code from a bunch of different websites.
There seems to be a problem with the system.schedule method (the last line of code).
It says "Error: Compile Error: expecting a right parentheses, found 'Daily Commision Check' at line 21 column 16"
refering to the last line of code
system.schedule('Daily Commision Check', s, m);
Here is my code:
global class AccountReviewScheduler implements Schedulable
{
global void execute (SchedulableContext ctx)
{
sendEmail();
}
public void sendEmail()
{
if (Account.Next_Account_Review_Date_c == System.today().addDays(14))
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Mail.setTemplateId('00XF0000000LfE1');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail });
}
}
newScheduledClass m = new newScheduledClass();
//schedule set for 2am everyday //
String s = '0 0 2 * * ?';
system.schedule('Daily Commision Check', s, m);
}
Thanks,
Angelika
Not sure why you are trying to schedule the class from within your class itself.. You can have your class as follows and then schedule it using execute anonymous -
global class AccountReviewScheduler implements Schedulable
{
global void execute (SchedulableContext ctx)
{
sendEmail();
}
public void sendEmail() { if (Account.Next_Account_Review_Date_c == System.today().addDays(14)) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); Mail.setTemplateId('00XF0000000LfE1'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail }); } }
}
then execute the following code from developer console -
AccountReviewScheduler m = new AccountReviewScheduler();
String s = '0 0 2 * * *';
system.schedule('Daily Commision Check', s, m);
Let me know if this works.
Rakesh Aggarwal
www.rakeshaggarwal.com
newScheduledClass m = new newScheduledClass();
//schedule set for 2am everyday //
String s = '0 0 2 * * ?';
system.schedule('Daily Commision Check', s, m);
Above code in your class is written directly under the class definition which is not allowed logically. You can only declare data members or a inner class under class. Code, statements can be written only in methods body or constructor.