You need to sign in to do that
Don't have an account?
David Jahnke
Update Opportunity Stage with Workflow Trigger
I am looking for the easiest way to update the opportunity stage based on how many days we are away from the close date.
So if the opportunity has a stage of "Quoted" and
If close date is less than 30 days away set stage to HOT
If close date is 30 to 120 days away set to WARM
If close date is greater than 120 days away set to COLD
Thanks!
So if the opportunity has a stage of "Quoted" and
If close date is less than 30 days away set stage to HOT
If close date is 30 to 120 days away set to WARM
If close date is greater than 120 days away set to COLD
Thanks!
If you want to achieve this with workflow you need to write 3 workflows.
Because Stage is a picklist field ,if you want a trigger then try this code.
There might be some typo errors please check before you use this code.
Thanks
Anil.B
There is no need of workflow if you use this trigger.
This will fire when ever a record is edited or created and if the conditions are meet then it will update the concerned field.
Thanks
Anil.B
Using a trigger is not the best option cause you have to update the records to change the field value.
If you don't update a record, you can encounter the situation in which Stagename is COLD and delay before closing date is only 1 day!
A formula field should be better cause it's evaluated each time you query the record, giving you the correct value even if the record have not been updated for a long time.
For example, you can define a custom field (let's say newStagename) as a text formula field with this kind of code: Hope this helps,
Fred
Maybe there is a better way to write this formula but at least I think we have to arrange it like this if we want the correct result: Hope this helps and happy new year!
Fred
If not, you have two (not so clean) options:
1. write an apex trigger but you have to figure out the exact trigger even that should fire off your change
2. define a workflow rule(s) on Opportunity Object, set formula (that evaluates to true or false) and update stagename to a pre-determined value. The downside is that you the worklow rule only fires in a create or edit situation.
Hi David,
You have to go with a daily batch cause no trigger fires when a formula field is evaluated (there is no update).
Good luck!
Fred
How do I create a 'batch' to force this to update the records that have not been edited once per day?
Have a look at schedulable apex http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htmor System.scheduleBatch method http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm#apex_batch_scheduleBatch_section.
The idea is to to insert a record or update a field to fire your workflow at the scheduled time.
Fred