You need to sign in to do that
Don't have an account?
DaveSt
Apex trigger update problem
Hi,
I am attempting to write a trigger on a custom object but it doesn't seem to being updating - my logic must be flawed in some way. The basic premise is that I have 2 checkbox fields that are updated depending on if a date field ( on the same object) falls within the bounds of either THIS_QUARTER or NEXT_QUARTER. My code looks like this:
Any help would be much appreciated,
Thanks
Dave
I am attempting to write a trigger on a custom object but it doesn't seem to being updating - my logic must be flawed in some way. The basic premise is that I have 2 checkbox fields that are updated depending on if a date field ( on the same object) falls within the bounds of either THIS_QUARTER or NEXT_QUARTER. My code looks like this:
trigger SM_Ident_Quarter on ScheduleMirror__c (before insert, before update) { for(ScheduleMirror__c SchedMirr : Trigger.New){ // if the schedule date is in This Quarter then update the this quarter flag for( ScheduleMirror__c s: [SELECT ID, Current_Quarter__c, Next_quarter__c, schedule_date__c from schedulemirror__c where schedule_date__c = THIS_QUARTER]){ if(s.id != null) s.Current_Quarter__c = TRUE; } // if the schedule date is in Next Quarter then update the next quarter flag for( ScheduleMirror__c sm: [SELECT ID, Current_Quarter__c, Next_quarter__c, schedule_date__c from schedulemirror__c where schedule_date__c = NEXT_QUARTER]){ if(sm.id != null) sm.Next_quarter__c = TRUE; } } }I feel this should be quite simple but I think I am missing something fundamental.
Any help would be much appreciated,
Thanks
Dave
Try this code then.
Regards
All Answers
However, these periods are dynamic so presumably by tomorrow all of your current quarter/next quarter flags may be incorrect anyway. It sounds like you want a schedueld job to process these records every night and update their status accordingly.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
I haven't noticed that :( sorry
Try this code,
Let me know if it solved your problem.
Regards
Thanks for the suggestion but it complains about the date literal being used in this context.
"Variable does not exist: THIS_QUARTER"
Do I have to define this as a formula upfront and reference the variable?
Thanks
Dave
Try this code then.
Regards