+ Start a Discussion
Katie KourtakisKatie Kourtakis 

scheduled job not working

Hello, I created a scheduled job to run every sunday. The code creates an attendance record for each program participant for each day they are signed up for that week. I tested the code and recieved 85% code coverage. I deployed the code to production and the first sunday it did not run at all. I then scheduled it to run from the scheduled job interface. It ran this past sunday but it did not create any attendances. Any help would be appreciated.

global class createSoulAttendance implements Schedulable {
    public static final String CRON_EXP = '0 0 12 ? * SUN';
    global static String scheduleIt() {
        createSoulAttendance job = new createSoulAttendance();
        return System.schedule('Soul Attendance', CRON_EXP, job);
    global void execute(SchedulableContext ctx) {
        //Create List to store Program Enrollment Ids
        List<id> enroll = new List<id>();
        //Find all attending Soul Participants with Status Confirmed
        for(Program_Enrollment__c enrollId : [SELECT ID FROM Program_Enrollment__c WHERE Campaign__r.Name = 'Soul Studio'
                                              AND Status__c = 'Confirmed']) {
        //Create List to store Volunteer Shift Ids
        List<id> vol = new List<id>();

        //Find Volunteer Shift Ids and add them to the list
        for(GW_Volunteers__Volunteer_Shift__C volId : [SELECT ID FROM GW_Volunteers__Volunteer_Shift__C  WHERE Program__r.Name = 'Soul Studio'AND Shift_Start_Date__c > TODAY 
                       AND Shift_Start_Date__c = NEXT_n_DAYS:7]){
        //Create Attendance for each program enrollment
        //Loop through enrollments
        for(Integer i = 0; i < enroll.size(); i++) {
            Program_Enrollment__c ProEnroll = new Program_Enrollment__c();
            ProEnroll.Id = enroll[i];
            //Loop through Volunteer Shifts
            for(Integer j = 0; j < vol.size(); j++) {
                GW_Volunteers__Volunteer_Shift__c volunteerShift = new GW_Volunteers__Volunteer_Shift__c();
                volunteerShift.Id = vol[j];
                //Create attendance for each enrollment
                Attendance__c att = new Attendance__c(Session__c = volunteerShift.Id, Program_Enrollment__c = ProEnroll.Id);
                //Insert Attendance
                insert att;

Best Answer chosen by Katie Kourtakis
Neha AggrawalNeha Aggrawal
Hi Katie,

Can you check Apex jobs in setup. You should find some error logs for your scheduled job there.

All Answers

Neha AggrawalNeha Aggrawal
Hi Katie,

Can you check Apex jobs in setup. You should find some error logs for your scheduled job there.
This was selected as the best answer
Katie KourtakisKatie Kourtakis
Hi Neha,

Thanks for pointing me in the right direction! I found an error log that states I have too many DML statements. I think I have to create a list of all new attendance records and then insert the list instead of inserting each record one by one.