Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs
24 votes
Accepted

How to test a scheduler which runs a batch?

I had a similar problem before which I solved by explicitly calling the execute method of my Schedulable class. Try something like this: Test.startTest(); AccountBatchScheduler abs= new ...
smukov's user avatar
  • 5,583
18 votes
Accepted

CRON to schedule batch class to run everyday at 10PM

For daily 10 PM 0 0 22 * * ? * first 0 for seconds second 0 for min third 22 for hours i.e. 10 PM you can use http://www.cronmaker.com/ for generating cron expression for more detail check ...
Ratan Paul's user avatar
  • 22.7k
17 votes

CRON to schedule batch class to run everyday at 10PM

Adding an answer because I always end up here and then have to look through the docs to remember the syntax: Cron Format: second minute hour day_of_month month day_of_week optional_year Format ...
NSjonas's user avatar
  • 10.2k
16 votes

How to test a scheduler which runs a batch?

Thanks for posting the question, this is a weird one. As the Salesforce documention says, Test.stopTest() should force asynchronous processes to run. It works for Apex Batch on its own, and it works ...
codeulike's user avatar
  • 1,137
14 votes
Accepted

Apex Batch - Is execute method called if start returns 0 results?

No. Execute will not be called unless at least one non-null item is available for processing. You'll have to come up with an alternative method. As a corollary to this statement, "scope" will never be ...
sfdcfox's user avatar
  • 493k
13 votes
Accepted

System.LimitException: Too many queueable jobs added to the queue

As you are chaining the jobs you have limit of 1 on child jobs. When chaining jobs, you can add only one job from an executing job with System.enqueueJob, which means that only one child job can exist ...
balinder singh's user avatar
8 votes
Accepted

Scheduling a Batch job at a particular time

You need to transform your datetime to the schedule format. More info here Example String day = string.valueOf(system.now().day()); String month = string.valueOf(system.now().month()); String hour =...
brovasi's user avatar
  • 5,675
8 votes
Accepted

Scheduling a batch process using UI- Which timezone does it schedule on?

The apex developer guide shows that scheduled jobs follow users time zone The System.Schedule method uses the user's timezone for the basis of all schedules. The easisest way would be to use a ...
Mohith Shrivastava's user avatar
8 votes

Ghost processes / batch processes (NA34 and NA39)

Not sure this is worthy of an answer, but too much to put as a comment. The only time I have seen anything remotely similar was with this and I was able to prove to support that a job had run and ...
Phil Hawthorn's user avatar
8 votes
Accepted

Ghost processes / batch processes (NA34 and NA39)

Seems I got some attention after submitting a case or this post or whatever, just got this notification: A bit late but at least I know the cause On March 16, 2017, Salesforce identified a ...
Eric's user avatar
  • 54.2k
8 votes

First error: Exceeded maximum time allotted for callout (120000 ms)

The callout timeout is tricky, because it applies both to single callouts and as a cumulative limit across a transaction: The maximum cumulative timeout for callouts by a single Apex transaction is ...
David Reed's user avatar
  • 93.1k
8 votes
Accepted

Scheduled Apex with one-time execution not being executed

FURTHER UPDATE: It seems that, whilst there is some sympathy from within Salesforce, the Salesforce PM and R&D team responsible believe this is a "feature enhancement", not the reporting ...
Phil W's user avatar
  • 36.6k
8 votes
Accepted

executeBatch method returning invalid id 000000000000000

This error seems to occur when a batch job is moved to the flex queue. When it enters the flex queue, it tries to acquire a flex queue token. If it fails to receive the token, this error is thrown and ...
Swetha Maddali's user avatar
7 votes

How to test a scheduler which runs a batch?

It's not going to run the batch. Since you have already tested the batch actions separately, you just need to query for the CronTrigger and verify it got scheduled. That's all that Test.stopTest() ...
Adrian Larson's user avatar
  • 150k
7 votes
Accepted

Cron Schedule Mondays 6AM

Add the Schedulable interface, then you can schedule the class in the Setup screen or by writing some execute anonymous code: public class BatchCount implements Database.Batchable<SObject>, ...
sfdcfox's user avatar
  • 493k
7 votes
Accepted

Testing a batch job which is scheduled through Handler class

It's not going to run the batch. You should test the batch actions separately. In this case, you just need to query for the CronTrigger and verify that it did, indeed, get scheduled. static ...
Adrian Larson's user avatar
  • 150k
7 votes
Accepted

Delete Old Scheduled Jobs from Batch Class

To clean up the list, you can purge the old jobs: global void finish(Database.BatchableContext BC) System.purgeOldAsyncJobs(Date.today()); You should only be calling System.abortJob to cancel jobs ...
sfdcfox's user avatar
  • 493k
6 votes
Accepted

Too many DML rows: 10000

That limit is for the entire transaction. So if you have one DML Operation with 10,000 rows, you cannot perform any other operations in that transaction. In your first example: Database.insert(...
Adrian Larson's user avatar
  • 150k
6 votes
Accepted

Schedule deployment change set

You can use the Force.com Migration Tool (ant) and write a small script to do this. The steps would be: ant retrieve from the source org ant deploy to the target org You would need somewhere to run ...
Kevin Boyle's user avatar
  • 1,311
6 votes

batch class is failing due to time while processing SOQL due to timeout error

There are a number of things you can do to improve the performance of your SOQL query. The most effective will be to understand how to diagnose it yourself, because how to solve your issue depends on ...
Nick C's user avatar
  • 6,700
6 votes

Scheduling a Batch job at a particular time

I usually include a few helper methods in any Schedulable class that needs to run at a given time as determined by Apex logic that's more complex than a simple cron expression. You can then call ...
JCD's user avatar
  • 3,384
6 votes
Accepted

Schedule a batch every 30 mins doesnot work

You are right, you will need two schedule statements to run the scheduled job every 30 minutes. System.schedule('Scheduled Job 1', '0 0 * * * ?', new ScheduledClass()); System.schedule('Scheduled Job ...
jagmohan's user avatar
  • 1,063
6 votes
Accepted

Handling the exception in my scheduler Class

This is realistically impossible. The reason why, of course, is Governor Limits. The way your code is written, if a governor limit hits you, you're dead in the water, indefinitely, until someone ...
sfdcfox's user avatar
  • 493k
6 votes

Maximum Number of Email Invocations Exceeded

The easiest fix for this would be to declare a List<Messaging.SingleEmailMessage> outside your for loops. Inside your iterations, rather than calling Messaging.sendEmail() each turn, you'd add ...
Dan Jones's user avatar
  • 7,217
6 votes
Accepted

Apex class's behavior mysteriously changing after debug statement removed

I believe it's because you're using the string data type instead of the Id data type, and thus triggering some sort of error in the system that debugging fixes (e.g. because they are then identified ...
sfdcfox's user avatar
  • 493k
6 votes
Accepted

Current state of reliable execution scheduling

For my SObjectWorkQueue I am using batch chaining and serialized work records. It’s not a new approach but worked very reliably in the past for me. Not sure if I ever saw this penalty. https://github....
Robert Sösemann's user avatar
6 votes
Accepted

Test Class Id Error

leads is a List<Lead>, and lists (along with other collections) do not have Ids. The records they contain might, but the list itself will not. Beyond that, SObject records do not have Ids until ...
Derek F's user avatar
  • 62k
6 votes
Accepted

Order of constructor execution for a class that implements a batchable as well as scheduleable interface

This method: global void execute(SchedulableContext SC){ testBatch currentInstanceOfBatch = new testBatch(); Database.executeBatch(currentInstanceOfBatch,currentInstanceOfBatch....
David Reed's user avatar
  • 93.1k
6 votes
Accepted

How can I schedule a batch for every 2h (to run at half past?)

Generally speaking, CRON expression allows to specify minutes and hours of the job. For minutes, it is possible to specify at which minute of an hour job should be run. For hours, hours can be ...
kurunve's user avatar
  • 4,319
6 votes
Accepted

Can I define the order when using two batches in the Schedule Class?

salesforce doesn't guarantee the order of execution of batches in your case. It is possible to implement using batch chaining. In order to send for execution second batch after the first batch, you ...
Oleksandr Berehovskyi's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible