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
deepak1.3956330618074822E12deepak1.3956330618074822E12 

Trigger for date related fields

I have created a field called Hold Release Date. The Status field in the case has an entry Hold.
I am comparing the Hold Release Date to Today and trying to trigger a field update that moves from Hold to Open. But this is not happening.
Mainly because the workflow rule evaluates only for the below Evaluation Criteria
a) Created
b) Created and everytime its edited
c) Created, and any time its edited to subsequently meet criteria

Since after moving the Case to Hold status and after putting Hold Release Date, the case is not touched i.e there are no edits to that case. Since there are no edits to the case, none of the evaluation criteria is met and workflow rule is not triggered.

Example: When I put a case in Hold for lets say 7 days, the Hold Release Date would be after 7 days. In these 7 days or even probably more than 7 days, the case will not be edited at all. So the Hold Release Date is missed because no triggeres on the 7th day to move the Hold state to Open state.

Now, Salesforce support says that i can do this only using triggers.
I am new to triggers and trying to understand the Apex code (i am not a "coder" :-))
After looking into some apex triggers, i wrote my own simple code as below

trigger HoldRelease on Case (before insert) {
if (case.Hold_Release_Date__c = 'TODAY'){
case.Status = 'Open';}
}

So, when Hold Relase Date is Today, i can trigger a field update to Status to go to Open and then trigger an email.

But salesforce seems to be not liking it and giving an error which i am not able to make it out

Error Error: Compile Error: Expression cannot be assigned at line -1 column -1

Can anybody help with the above code or give me the code that can do the above job? Your help is appreciated.

Regards
Deepak
Blake TanonBlake Tanon
Dates are a pain, you need to format all of them in apex to make sure they are in the right timezone.  When you compare say system.today() to date_field__c that has a date of today, the system.today() will return 2014-03-23 20:00:00 where the date field will return 2014-03-24 00:00:00.  Because the date field is returning the earliest point in the date for teh day, midnight and the system.today() is going to return the same point but with the GMT offset.  

If you put in this:
system.debug('# # # system date: '+system.today())
;system.debug('# # # field date: '+case.Hold_Release_Date__c);

you can see what the return is in the debug log.