Fetch the size & Count of the records of the opportunity using Batch apex

By | January 10, 2020

Hi, here we have shown, how to Fetch the size and Count of the records of the opportunity and save the count and size size as Name in Account using batch apex.

Apex controller

Global class optyBatch implements Database.Batchable<Sobject>,Database.stateful{
    public integer Count=0;
    public static integer size=0;
    Global Database.QueryLocator Start(Database.BatchableContext bc){
        return Database.getQueryLocator('select id,name from Opportunity');
    Global void execute(Database.BatchableContext bc,list<Opportunity>Scope){
        for(Opportunity opp:Scope){
    Global void finish(Database.BatchableContext bc){
      Account acc = new Account();
        insert acc;


Open debug Anonymous Window

optyBatch cd = new optyBatch();


here 10 is the batch size…

Leave a Reply

Your email address will not be published. Required fields are marked *