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

Timer functionality in Apex


Is there a timer functionality in Apex?  I want to be able to schedule some operations on a periodic basis.

The second related question is to invoke something that is only accessible from a UI control (from an installed package for which either the backend code or the web service is not available).  Is it possible to simulate a mouse click based on a timer event?

Thanks in advance!
Ron HessRon Hess
This is not a current feature, you can register this idea on the idea exchange, i think it's already listed there, in which case please vote for it.

No, Apex code cannot simulate a browser click.

Thank you Ron.  I suspected as much - are you aware of any "clever" ways to simulate timer functionality?  This is a fairly standard/required functionality so hopefully it gets added soon

While I haven't actually tested this solution, we were considering the same issue for simulating cron jobs. What we came up with was the idea of incorporating a call to something link myCron.isItTime() into the trigger elements of multiple frequently added or updated objects (Account, Opportunity, Lead, etc) so that, given enough user activity, you can simulate a timed refresh. the advantage of this as a work-around is that it functions on the logic that there's no real reason for the data to be updated if no one's looking at it.

If you have a lot of user activity, this could run into governance issues, so you would probably want to have the triggered calls going to a wrap around function that merely checks whether enough time has passed to do the rest of the procedures.

If this isn't clear, let me know and i'll clarify. Would love to hear back about how it works out if you decide to try it...
You might want to look at creating a local service or daemon, such as a windows service, hosted in your organization that will hit the SFDC API at specified intervals.  Because this would be 100% custom code in the language of your choice (as long as it can consume Salesforce WSDL), you could even simulate mouse clicks, as long as you're comfortable writing screen scraping code.

Is it possible to create a clock in apex class?