I am getting the following error for a Scheduled Apex Job and don't know how to fix it (not a developer, just adapting some existing code). The aim is to update a field every night to trigger workflows, etc. I think the error could be around the field I want to update (as there are currently some records without a value in this field), but I could be wrong as the error mentions Object.
I've found similar queries but haven't figured out how to adapt answers for my specific case.
The full error is:
Scheduler: failed to execute scheduled job: jobId: 7071X000002o0om, class: common.apex.async.AsyncApexJobObject, reason: Attempt to de-reference a null object
Any suggestions of what to do / how to tweak the code greatly appreciated!
global class checkYoungPersonAllocations Implements Schedulable {
global void execute(SchedulableContext sc) {
checkMyAllocations();
}
public void checkMyAllocations() {
List<Young_Person_Allocation__c> affected = [SELECT Id, Name, Trigger_Field__c, Trip_Start_Date__c
FROM Young_Person_Allocation__c
WHERE Trip_Start_Date__c >= TODAY];
for(Young_Person_Allocation__c thisAllocation : affected) {
thisAllocation.Trigger_Field__c = thisAllocation.Trigger_Field__c + 1;
}
update affected;
}}