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
m 10m 10 

is it possible to run batch every minute

Hi Team ,
Could you please help me below apex batch job need to run every minute
but no lock it's executng every 1hour please find below screenshot
User-added image
global class ServiceClaimBatchimplements Database.Batchable<SObject>, Database.AllowsCallouts, Database.Stateful{

    private  void rescheduleBurstSMSResponse(){
        try{
        Datetime dt = system.now().addMinutes(1);          
        String day = string.valueOf(system.now().day());
        String month = string.valueOf(system.now().month());
        String hour = string.valueOf(system.now().hour());
        String minute = string.valueOf(system.now().minute());
        String second = string.valueOf(system.now().second());
        String year = string.valueOf(system.now().year());
        
        String cronExpression = '' + dt.second() + ' ' + dt.minute() + ' ' + dt.hour() + ' ' + dt.day() + ' ' + dt.month() + ' ? ' + dt.year();
        String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
 
            
            if(Test.isRunningTest()) {
            //This will throw Divide by 0 error and code will move to catch block
            Integer divideError = 123/0;
        }
                System.schedule(cronExpression, strSchedule, new ScheduleServiceClaim());
        }catch(Exception ex){
            System.debug(ex);
            System.debug(ex.getMessage());
            System.debug(ex.getLineNumber());
        }
    }


 ...........................................................
global class ScheduleServiceClaim implements Schedulable {
    global void execute(SchedulableContext sc){
        Database.executeBatch(new ServiceClaimBatch());
    }
}

Will appricate as best answer please help me it is killing my head 
RituSharmaRituSharma
Yes, you can. You have to schedule the job 60 times like below:

System.schedule('Scheduled Job 1', '0 1 * * * ?', new scheduledTest());
System.schedule('Scheduled Job 2', '0 2 * * * ?', new scheduledTest());
System.schedule('Scheduled Job 3', '0 3 * * * ?', new scheduledTest());
System.schedule('Scheduled Job 4', '0 4 * * * ?', new scheduledTest());

I would suggest you to keep longer gap since executing a job might take more than a minute so it's like previous job is not over and new one is started. It might case locking issues.
AbhishekAbhishek (Salesforce Developers) 
By default, you can run the apex job every 1-hour using cron expression but you can schedule this job 12 times at 5 min duration. However, only 100 Apex classes can be scheduled concurrently and 5 batch Apex jobs can be queued or active concurrently.

http://resources.docs.salesforce.com/198/10/en-us/sfdc/pdf/salesforce_app_limits_cheatsheet.pdf
Aman Gupta 161Aman Gupta 161
Yes It is possiable. 
Salesforce does not allow to schedule bach class every minute. But you can use trick to schedule it for every minute.

Use a function and run a for loop to schedule the class for every minute for 1 hr. 
Example :
Like  schedule 4.05 ---> after one hr it will run at 5.05.
then for 4.06 ---> it will run again at 5.06.
for 4.07 ---> will again run at 5.07.

This is how schedule it for 60 times for every minute. Every minute will execute after 1 hr which is allowed.
Here is the function and CRON EXPRESSION that runs every minutes
 
// CRON EXPRESSION to schedule per minute in salesforce

global static void runSchedule(){

        for(Integer i =0; i < 60; i++){
           String CRON_EXP = '0 '+i+' * * * ?'; 
        	GenericRecordSchedulableClass gensSch = new GenericRecordSchedulableClass();
        	System.schedule('Generic every min'+i, CRON_EXP, gensSch);
        }
        
    }

If it helped you. support this answer.