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
sri vinod korlakunta 15sri vinod korlakunta 15 

how to create a reporting snapshot with more than 100 fields using batch apex?

bhanu_prakashbhanu_prakash
Hi Sri,

Mark as best answer, If it resloves  !!

You need to query your requried fields into batch class
you batch need to be similar
global class SnapshotOpenCasesBatch implements Database.Batchable<sObject> 
 {

    //Gather all the records I want to use in the execute method
    global Database.QueryLocator start(Database.BatchableContext BC) 
    {
        return Database.getQueryLocator([SELECT ID, OwnerID, Name, Case_Type__c, Subtype__c, Status__c, Reason__c, Case_Age_Days__c, CreatedDate FROM Custom_Case__c WHERE Status__c in ('New', 'Work in Process', 'Escalated', 'Solution Proposed/Validation') ORDER BY CreatedDate ASC]); // Production source field is Created_Date__c
    }

    global void execute(Database.BatchableContext BC, List<Custom_Case__c> openCases) 
    {

            //for creating new Snapshot batch.
            List<Snapshot_Open_CASE__c> newSnapshot = new List<Snapshot_Open_CASE__c>();

            //create map collection to pair case owner ID and full name 
            Map<ID, String> userMap = new Map<ID, String>(); 

            //add all OwnerId values from openCases List to the set of userIds for query
            Set<ID> userIdSet = new Set<ID>();

            for (Custom_Case__c c : openCases) {
                userIdSet.add(c.OwnerID);
            }

            //Go get all the User ID + name combos from the set of Ids created above
            List<User> userList = new List<User>([SELECT ID, Name FROM User WHERE ID in : userIdSet]);

            //Load userMap with the results of the query above
            for(User u : userList){
                userMap.put(u.id, u.Name);
            }   

            for (Custom_Case__c c : openCases) {
                Snapshot_Open_CASE__c snap = new Snapshot_Open_CASE__c();
                snap.CASE_ID__c = c.ID;
                snap.OwnerID__c = c.OwnerID;
                snap.Case_Number__c = c.Name;
                snap.Case_Type__c = c.Case_Type__c;
                snap.Subtype__c = c.Subtype__c;
                snap.Status__c = c.Status__c;
                snap.Reason__c = c.Reason__c;
                snap.Case_Age_Days__c = c.Case_Age_Days__c;
                snap.Created_Date__c = c.CreatedDate.date(); // Production source field is Created_Date__c // also convert datetime to date
                snap.Name = String.valueof(Date.today()); // Use execution date as unique id

                // add the user name
                snap.Owner_Full_Name__c = userMap.get(c.OwnerId);

                //load up the data for insert
                newSnapshot.add(snap);
                }

            insert newSnapshot;
            }

    global void finish(Database.BatchableContext BC) {
        system.debug('Batch Job is Complete');
    }
}

Thanks, 
Bhanu Prakash
visit ForceLearn.com