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
dinesh S 31dinesh S 31 

Could please let me know how to get the logfile from evenlogfile in apex coding through batch class. // Blob s = 'Select Id,LogFile,EventType from EventLogFile'; I am not able to get the logfile aas string pass it to executte metthod

Could you any please let me know how to get the logfile from eventlog and sent it to execute method

global class batchEventLog implements Database.Batchable<sObject> {


    list<string> headersList{get;set;}
    Set<String> csvHeader = new Set<String>();
    String combinedDataAsHex = '';
    Blob combinedDataAsBlob;
    String csvFileData ='';
    String userEmail ='';
    String newSetStr = '' ; 
    List<String> newSetStrList = new List<String>();
    String noOfDays = '';
    Set<String> strEventTypes = new Set<String>();
   // HttpRequest req = new HttpRequest();
    public list<String> eventTypelist = new list<String>();
    
    
    
    
   
    global Database.QueryLocator start(Database.BatchableContext BC) {
    
    
    System.debug('I am inside the start method');
    
    List<String> eventTypesArr = new List<String>();
        List<Event_Log_File_Configuration__mdt> eventconf = new List<Event_Log_File_Configuration__mdt>([SELECT Event_Types__c, Duration_in_days__c, User_Email__c FROM Event_Log_File_Configuration__mdt where DeveloperName = 'Event_Log' limit 1]);
        userEmail = eventconf[0].User_Email__c;
        noOfDays =  eventconf[0].Duration_in_days__c;
        String eventTypes = eventconf[0].Event_Types__c;
        if(eventTypes.contains(',')){
            eventTypesArr = eventTypes.split(',');
        }
        else{
            eventTypesArr.add(eventTypes);
        }
        for(String evStr : eventTypesArr){
            strEventTypes.add(evStr);
        }
    
     for(String evStr : eventTypelist){
            strEventTypes.add(evStr);
        } 

       System.debug('::::Event Type Values::::' + strEventTypes);
        for(String str : strEventTypes){
            newSetStr += '\'' + str + '\',';
        
       newSetStr = newSetStr.lastIndexOf(',') > 0 ? '(' + newSetStr.substring(0,newSetStr.lastIndexOf(',')) + ')' : newSetStr ;
        }
       System.debug('***************The value of newSetStr is '+newSetStr); 
       newSetStrList.add(newSetStr);
        system.debug('**********************newSetStrList'+newSetStrList);
  
      String query = 'Select Id,LogFile,EventType from EventLogFile';
    
      //  Blob s = 'Select Id,LogFile,EventType from EventLogFile';
        
  //      string query = b.tostring();
          //query = EncodingUtil.base64Decode(EncodingUtil.base64Encode(b)).toString();

        return Database.getQueryLocator(query);
    }
   
    global void execute(Database.BatchableContext BC, List<EventLogFile> scope) {
    
          System.debug('Iam inside the execute method');
         for(EventLogFile a : scope)
         {
             System.debug('The value of event log  file'+a.EventType);
             System.debug('The value of log file is '+a.LogFile);
                         
         }
        
    }   
    
    global void finish(Database.BatchableContext BC) {
    }
}
Shaik Naga janiShaik Naga jani
Hi Dinesh,
I tested below code it is working to me, you can update SOQL based on your requirement.
global class EventLogFileBatch implements Database.Batchable<sObject> {
    public list<EventLogFile> start(Database.BatchableContext bc) {
        return [Select Id,LogFile,EventType from EventLogFile];
    }
    
    public void execute(Database.BatchableContext bc, list<sObject> scope) {
        for(EventLogFile evntFile : (list<EventLogFile>)scope) {
            System.debug('evntFile =====> '+ evntFile);
        }
    }
    
    public void finish(Database.BatchableContext bc) {
        
    }
}

Kindly mark this as solved if the reply was helpful.
Thanks
Shaik