You need to sign in to do that
Don't have an account?

eplacing a work flow trigger wiht an apex trigger
Ok, I have a workflow rule that sends out an email regarding contracts that are due to expire. This rules is based on a custom formula field in the contracts object. The formula calculates the remaining months for a contract.
How can I get this rule to trigger even though the record is not physically edited or created.
What we have to do right now is wipe out all the contracts every night and rebuild them with a data push from our servers and that will trigger the rule to look at each record and it's respective "Month's remaining" field value and trigger the email or not.
Has anybody encountered this problem and be able to solve it wiht an apex trigger? I have not prior experianc eusing or implemnting APex triggers so please keep that in mind when you point me in the right direction.
Thank you very much
Anthony
Use a batch job instead, and schedule it to run nightly.
========================================================
A developer can now employ batch Apex to build complex, long-running processes on the Force.com platform. For example, a developer could build an archiving solution that runs on a nightly basis, looking for records past a certain date and adding them to an archive. Or a developer could build a data cleansing operation that goes through all Accounts and Opportunities on a nightly basis and reassigns them if necessary, based on custom criteria.
Batch Apex is exposed as an interface that must be implemented by the developer. Batch jobs can be programmatically invoked at runtime using Apex.
Can you give me some usefull tips on how to go about doing that? maybe some good examples.
Thank you
Couldn't you do this with a time based workflow? We've got a similar case and our contracts have an expiration date on them when they are created. The time based workflow is set up to send an email 5 days before the contract ends. I think this would be easier to do than set up a batch job.
Use another formula field and set the type to date and make that Today().
Create a workflow to monitor the field using evalute criteria...
ISCHANGED('DATEFIELDNAME'). this field will change everyday. Hence the record is updated each day automatically.
I understand the first part but im not sure where i would put the ISCHANGE in the workflow. all i am seeing is the usual criteria interface where i can pick a field on the left. the operand and the value on the right.
never mind. i see it now. thanks. ill try all methods and see which one works for us. THanks to everyone for your help.
Still a little confused. SO now i have a workflow that triggers when the new date field ISCHANGED but how does it evaluate the actual Months remaing field and only send of an email when that field equals my criteria?
would this work in the workflow formula AND (ISCHANGED( TriggerDate__c ) ,Months_Remaining__c = 3.00)
Another question is. THis rules only triggers if the records has been created or edited. What do they exactly mean by Edited? Is the fact that the date changed in the field containg the formula Today() enough to flag the record as edited?
How would i implement your solution? can you give me the details? thank you.
Ok, here i am again. I tried to implement a time based trigger but another problem cropped up. SF as of yet does not allow you to create a time based workflow trigger based on the contract end date. Only for contract start date. what a bummer. I have tried to add a field based on a formula Today() but that doesnt seem to make tke the records appear as "changed" to trigger the wrokflow trigger. THis is the syntax i have for the workflow rule "AND (ISCHANGED( TriggerDate__c ) ,Months_Remaining__c <= 3.00)" where TriggerDate_c is the field with the Today() formula in the contract object and the Months_Remaining__c <= 3.00 is to see if the lease is about to expire. THe Month_remaining field is a calculated field based on the start date and term . What else can i do?
thank you
Anthony
You can create a custom formula field that is just the contract end date. You can then create a time trigger on the custom field.
My understanding is that you can do it within a workflow:
-1: create a formula (Date) named 'End' and the formula is :Enddate
==> so you can use the endate in the time based workflow
2: create a workflow:
select :When a record is created, or when a record is edited and did not previously meet the rule criteria
formula: ( EndDate -today())>90
==> if you expect the email to be send 90 days before the EndDate
Time based workflow criteria: 90 days before the field 'End' (created in step1)
Action: your email
Activate and try it.
Use apex scheduler to write a class and schedule it on weekly/daily basis as you want.
I tried to reference Today() in an ischanged function, but it does not work. Formula fields are only updated when the record is accessed, so they aren't checked everyday. My solution to a somewhat similar problem the OP had was a trigger to set the date, then a time based work flow based on that field's date.