You need to sign in to do that
Don't have an account?
Jitendra
How to write a piece of code which will run after specific Time
Hi,
I need to write a piece of code which will get the List of Opportunity difrentiated by some criteria and want to email those records every weekends.
Its like Time Based coading.
I have read about time dependent Workflow triggers but it doesnt resolves my problem because it does not provide flexibility to write the Apex code.
I want to run the code once in every week.
Can anyone give some suggestions?
Thanks in Advance!
I need to write a piece of code which will get the List of Opportunity difrentiated by some criteria and want to email those records every weekends.
Its like Time Based coading.
I have read about time dependent Workflow triggers but it doesnt resolves my problem because it does not provide flexibility to write the Apex code.
I want to run the code once in every week.
Can anyone give some suggestions?
Thanks in Advance!
I've been able to combine workflow rules and Apex code to accomplish what you're looking for. I created a custom object called Scheduled Jobs which I use to set off the workflow rule. The workflow rule is triggered by a checkbox field called "Schedule". One of the fields in Scheduled Jobs is "Next Run Datetime" and there's a workflow rule that is set to run 0 hours after that datetime. When it runs, all it does is update a "Run Job" field which sets off the Apex code. Each time a job is run, in addition to whatever code I want run, I have Apex insert a new Scheduled Job record with the Next Run Datetime and Schedule = true, so the process starts over again. Since I have a few different jobs running this way, the Scheduled Job includes fields to indicate which method to run, the time it should be set off (I store it as military time and convert it to a datetime in the code). I even have a job which deletes old Scheduled Job records so it doesn't get too cluttered.
I included the code, minus some irrelevent bits, below. The intMagicNum is something I had to include because some of the methods I run have to be run in chunks otherwise they hit Apex governor limits. So, for instance, I have jobs that send out emails but I can only send out 10 emails at a time. Each time it's run, the method is tracking which users have been emailed and only emails people that haven't received it yet. So when it's done, it returns how many emails it actually sent and if that number = 10, the job is scheduled to run again immediately (there's generally a 15 minute delay) until everyone has been emailed (less than 10 returned). It's a workaround since Salesforce doesn't yet provide cron job-like functionality, but it works for now! Maybe more information than you were looking for, but I hope this helps.
Jessie
All Answers
I've been able to combine workflow rules and Apex code to accomplish what you're looking for. I created a custom object called Scheduled Jobs which I use to set off the workflow rule. The workflow rule is triggered by a checkbox field called "Schedule". One of the fields in Scheduled Jobs is "Next Run Datetime" and there's a workflow rule that is set to run 0 hours after that datetime. When it runs, all it does is update a "Run Job" field which sets off the Apex code. Each time a job is run, in addition to whatever code I want run, I have Apex insert a new Scheduled Job record with the Next Run Datetime and Schedule = true, so the process starts over again. Since I have a few different jobs running this way, the Scheduled Job includes fields to indicate which method to run, the time it should be set off (I store it as military time and convert it to a datetime in the code). I even have a job which deletes old Scheduled Job records so it doesn't get too cluttered.
I included the code, minus some irrelevent bits, below. The intMagicNum is something I had to include because some of the methods I run have to be run in chunks otherwise they hit Apex governor limits. So, for instance, I have jobs that send out emails but I can only send out 10 emails at a time. Each time it's run, the method is tracking which users have been emailed and only emails people that haven't received it yet. So when it's done, it returns how many emails it actually sent and if that number = 10, the job is scheduled to run again immediately (there's generally a 15 minute delay) until everyone has been emailed (less than 10 returned). It's a workaround since Salesforce doesn't yet provide cron job-like functionality, but it works for now! Maybe more information than you were looking for, but I hope this helps.
Jessie
Nice !
David
It solved my problem.
Thank you very much
I am sending the automaic Email to the users using Apex. I am able to send different emails to different user.
But i am not able to set the From field in the Apex Code.
Email is sent by the Trigger and trigger is activated by Workflow Rule.
It takes the name of last Logged in User by default to set the From field of the email.
Is there any Way to set the Name of default Workflow user or any User?
Please suggest any solution or work around if you know.
Thanks for quick reply.
I am also using the same line but it only displays the Name but it have email address of another user. and the user is not fixed. it is selected by last login.
eg:
With verison 16 of apex code, can you write an apex class and schedule it?