You need to sign in to do that
Don't have an account?
Dchris222
Apex Scheduler Problems
Have an apex class that has been tested to work, but I am having problems understanding the documentation for creating a Scheduler class. The documentation here makes it seem like all I have to do is create the following scheduler class, but when I schedule it to run in salesforce nothing happens. Any help would be appreciated.
Scheduler Class
global class OppPoliceScheduler1 implements Schedulable{ global void execute(SchedulableContext sc) { OppPoliceController O = new OppPoliceController(); } }
Apex Class
public with sharing class OppPoliceController { public void Opportunity() { List<Opportunity> Opptys2 = [SELECT id, LastActivityDate, Activity_Status__c, StageName, (SELECT id, CreatedDate from Feeds ) FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' ORDER BY LastActivityDate DESC]; for(Opportunity Op : Opptys2){ datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat datetime CreatedDate = Op.Feeds[0].CreatedDate; //Created Date in datetime format date d = Date.Today(); //Current Date Formated if(LastActivityDate == null || d > LastActivityDate.addDays(14) || d > CreatedDate.addDays(14)) { Op.Activity_Status__c = 'High'; } else if((d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)) || (d >= CreatedDate.addDays(7) && d < CreatedDate.addDays(14))) { Op.Activity_Status__c = 'Medium'; } else if(d < LastActivityDate.addDays(7) || d < CreatedDate.addDays(7)) { Op.Activity_Status__c = 'Low'; } else { Op.Activity_Status__c = 'Error'; } } update Opptys2; } }
Not sure what the previous post was referring to, but it looks like you forgot to call the opportunity method...
Please note - when you invoke the System.schedule method, it will return an ID that refers to the Crontrigger table. You can query this directly confirm execution times. I think you'll find the scheduler did fire - but no actual logic, other than the instantiation of OppPoliceController, was fired.
All Answers
i can see that u dont have database.execute metod in ur apex class.Add in ur main class
public void oppPolicecontroller()
{
oppPolicecontroller obj = new oppPolicecontroller();
ID batchprocessid = Database.executeBatch(obj);
}
Not sure what the previous post was referring to, but it looks like you forgot to call the opportunity method...
Please note - when you invoke the System.schedule method, it will return an ID that refers to the Crontrigger table. You can query this directly confirm execution times. I think you'll find the scheduler did fire - but no actual logic, other than the instantiation of OppPoliceController, was fired.
Thanks for your input!