You need to sign in to do that
Don't have an account?
dinesh 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) {
}
}
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) {
}
}
I tested below code it is working to me, you can update SOQL based on your requirement.
Kindly mark this as solved if the reply was helpful.
Thanks
Shaik