You need to sign in to do that
Don't have an account?
Victor Nguyen 13
Schedule an Apex class not on the list
Hi everyone,
I have a scheduled Apex class, but it's not on the Schedule list. Can you please help me what I did wrong?
I have a scheduled Apex class, but it's not on the Schedule list. Can you please help me what I did wrong?
global class LatePayment implements Schedulable { global void execute(SchedulableContext ctx) { Date AcceptedDate; //Schedule the class to run on every Friday at 11:59PM String Cron_exp = '59 59 23 ? * FRI'; String JobID = System.Schedule('Check Late Payment', Cron_exp, new LatePayment()); //Creating Registration Deadlines Date table List<hed__Term__c> lstTerm = [SELECT Id, Name, Application_Session__c, Application_Year__c, Registration_Deadlines__c FROM hed__Term__c WHERE Registration_Deadlines__c < TODAY ORDER BY Registration_Deadlines__c asc]; //Creating a list of all Opp that are under Acceptance Letter Issued and Visa Pass stage List<Opportunity> lstOpp = [SELECT Id, Deferred__c, RecordTypeId, Name, StageName, Accepted_Letter_Issued_Date__c, Visa_Pass_Date__c, CloseDate, Late_Payment__c, I_am_applying_for_the__c, Year_of_Semester__c FROM Opportunity WHERE (StageName = 'Visa Pass' OR StageName ='Acceptance Letter Issued') AND RecordTypeId != '0126A000000xOkkQAE' AND RecordTypeId != '0126A000000xOkfQAE' ORDER BY CloseDate asc]; List<Opportunity> lstUpdate = new List<Opportunity>(); if (!lstOpp.IsEmpty()) { for (Opportunity opp : lstOpp) { if ((opp.RecordTypeId == '0126A000000xOkVQAU' || opp.RecordTypeId == '0126A000000JHdYQAW')) { if (opp.Deferred__c == false) { AcceptedDate = opp.Visa_Pass_Date__c; } else { AcceptedDate = opp.Accepted_Letter_Issued_Date__c; } } else { AcceptedDate = opp.Accepted_Letter_Issued_Date__c; } for (hed__Term__c terms : lstTerm) { if (opp.I_am_applying_for_the__c == terms.Application_Session__c && opp.Year_of_Semester__c == terms.Application_Year__c) { if (AcceptedDate < terms.Registration_Deadlines__c.addDays(-7)) { opp.Late_Payment__c = (terms.Registration_Deadlines__c.daysBetween(Date.today())+3) / 7; } else { opp.Late_Payment__c = AcceptedDate.daysBetween(Date.today()) / 7; } } } lstUpdate.add(opp); } update lstUpdate; } } }
Hi Victor,
As I can see in the code, you want to run this Scheduled on every Friday. Instead of writing Cron Expressions schedule it manually.
Go to --> Setup --> Apex Class --> Schedule Apex --> Select class to schedule and Time.
Remove Cron Expressions and System.schedule logic from the class.
Thanks,
Gaurav
Skype: gaurav62990
Thanks for the input. I know that I can do it in that way.
But I'm just curious what I did incorrectly that cause the Apex class can't be scheduled.