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
AbanteAbante 

Database batchable scope limit

Hello everyone,

 

 

In a  database batchable...How do I put a 5 records limit to the scope? 

 

global void execute(Database.BatchableContext info, List<Contact> scope)

 

 

Thanks in advance!

Best Answer chosen by Admin (Salesforce Developers) 
nick1505nick1505

Hi,

 

You can set the scope when you are exceuting the batch by creating it's object.

 

For example:

Id batchId = database.executeBatch(new SL_Batch_Contact(), 5);

where SL_Batch_Contact is my class name and 5 is my scope.

It will be processing only 5 records in one batch.

 

Thanks,

nicks1505

Certified Developer

All Answers

nick1505nick1505

Hi,

 

You can set the scope when you are exceuting the batch by creating it's object.

 

For example:

Id batchId = database.executeBatch(new SL_Batch_Contact(), 5);

where SL_Batch_Contact is my class name and 5 is my scope.

It will be processing only 5 records in one batch.

 

Thanks,

nicks1505

Certified Developer

This was selected as the best answer
AbanteAbante

Thank you Nick, It's really easy but I didn't know how to do It

 

Regards,

 

 

nick1505nick1505

Welcome!

Glad that it helped you:-)