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
SimrinSimrin 

Apex Scheduler sample code not working

public void testSchedule() {
        List<Object_C> pList= [Select date__c 
                                                FROM Object_C
                                                WHERE  UserId = :UserInfo.getUserId() ];
        for(Object_C test : pList) {
            if(test .date__c< Date.today()){
                test .column__c = 'DONE';
                update Object_C;
            }
        }
    }

I have a fucntion which checks if the date enetered is less than today.  If true then it will update column__c to Done.

I want to implement it as apex scheduler.

I followed below links with no scucess.

http://stackoverflow.com/questions/9126886/how-do-we-schedule-a-class-to-run-every-15-mins-in-salesforce
https://developer.salesforce.com/forums?id=906F00000008rTLIAY
 
global class certifiedToLapsedScheduler implements Schedulable{
    global void execute(SchedulableContext SC) {
        RecurringScheduleJob.startJob();   
        String day = string.valueOf(system.now().day());
        String month = string.valueOf(system.now().month());
        String hour = string.valueOf(system.now().hour());
        String minute = string.valueOf(system.now().minute() + 10);
        String second = string.valueOf(system.now().second());
        String year = string.valueOf(system.now().year());
        
        String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;
        String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
        System.schedule(strJobName, strSchedule, new certifiedToLapsedScheduler());
    } 
}

ERRRO: Method does not exist or incorrect signature: RecurringScheduleJob.startJob()

public class RecurringScheduleJob{
    public static void startJob(){
        String str = 'Job Started at : ' + system.now();
        Schedule_job__c obj = new Schedule_job__c();
        obj.name = str;
        insert obj;
    }
}
ERROR: Invalid type: Schedule_job__c


 

Best Answer chosen by Simrin
BDatlaBDatla
Hi Simrin,

ERROR: Invalid type: Schedule_job__c
I think your org is not having custom object Schedule_job__c

2) use global for the below class.
global class RecurringScheduleJob{

Regards,
BDatla



 

All Answers

BDatlaBDatla
Hi Simrin,

ERROR: Invalid type: Schedule_job__c
I think your org is not having custom object Schedule_job__c

2) use global for the below class.
global class RecurringScheduleJob{

Regards,
BDatla



 
This was selected as the best answer
SimrinSimrin
global class RecurringScheduleJob{
    public static void startJob(){
        String str = 'Job Started at : ' + system.now();
    }
}


I chage class to above.

I do not have any errors.

How can i run or start this class for first time.  Presently i am in sandbox but i will need to make sure that the method i use here will alow be ok foor production environment

BDatlaBDatla
Hi Simrinn,

You can find more information in the below article.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

I belive you just need to execute that particular method in the execute anonymous section .

Regards,
BDatla
 
SimrinSimrin
Whenever i try to edit my apex code, it promts me saying that 
This Apex class has batch or future jobs pending or in progress; This schedulable class has jobs pending or in progress.

How can i edit my apex code 
BDatlaBDatla
Please go to setup>schedule jobs and cancel any pending/in progress jobs.
SimrinSimrin
thank you