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
kathyanikathyani 

Scheduled Workflow

Hi,

I need to create a scheduled work flow which should fire a trigger and alert the user that something has happened. Also it should create a record in a table.

I searched for documentation but the steps are not clear. I vaguely understood the concept but what are the steps?  Can somebody send me an example and steps to accomplish this? What do I click sales force UI to create a scheduled workflow?

Thanks,
Kathyani

David VPDavid VP
The 'something has happened' would be your worklow rule criteria.

The workflow can then either do something like sending a mail to the user or update a field (which could in turn fire a trigger, but you'd have to check for that field in the trigger itself, make it an 'after update' one) ...
I would also use that trigger for creating the record you need (a workflow can update a field but not create an entire record).

-david-

kathyanikathyani
Can you please tell me if these steps are correct?
1. On SF UI, under work flows and approvals, I can create the work flow rule - if no activity happens in 14 days ( this is the condition)
2. Then create a work flow action - like notify the user/ send an email


Why and when do I need to write a trigger. If I want to update a row then I would need a trigger?

Any help would be appreciated.


thanks,
Kathyani
David VPDavid VP
Yes,
That looks good to me. You can create a time-based trigger to fire 14 days after the 'LastModified' date - that would tell you that there have not been any updates on the object for 14 dyas.
The action is indeed simply sending an email (don't forget to create an email template for that first)

If you want to update fields on the object that fired your workflow you do not need a trigger - just use the 'update field' action.


If you need to create some other record, you would need a trigger + some apex code.

Just try it, it's really easy.


-David
kathyanikathyani
I cannot do this using Sales force UI. Any idea how I can set this from the api?
David VPDavid VP

You will have to be a bit more specific and explain us what exactly you are trying to do, what you have done already, and what steps are blocking you.

I'm sure we'll find a way to get this working for you.

-David
kathyanikathyani
Sorry for not being clear. My manager does not want me to use SF UI to accomplish Scheduled workflow but rather it should be coded using the api.

This is the requirement:
Basically I have to check a table if any activity has taken place. If the activity stays as is and nothing has changed since 2 weeks then send an alert email to the user. It should also insert a record in another table.

Where do I code this, in the trigger? Where do I code the condition (of past 14 days), send an alert email? I am not clear where exactly the code should be written.



David VPDavid VP
OK,

I'm sticking to my story though :

"Basically I have to check a table if any activity has taken place. If the activity stays as is and nothing has changed since 2 weeks then send an alert email to the user."

-> This is exactly what time-based workflow is used for. Run it off the lastmodified date on your record. It would be a waste of time trying to rewrite the already existing (and powerful) workflow engine in code.

"It should also insert a record in another table."

-> You could probably have the above trigger also do a field update which in turn would fire an 'after update' trigger that could create and insert the record you want.

There are good examples on workflow in the Force.com Cookbook and the Help files in your environment.
Checkout the Apex developer's guide on how to insert records.

Hope this helps,


david