1

I am trying to create records in a Big Object using a Batch class.

However, when executing the Database.InsertImmediate() command, the error below occurs:

enter image description here

Just as a note, the Database.InsertAsync() doesn't work either.

What can it be? Here is the code:

global class LogErrorBatch implements Database.Batchable<sObject>, Schedulable{

private static final Integer DAYS_AGO = Test.isRunningTest() ? 0 : 0;
private static List<BackupLogErro__b> lstBkpLog = new List<BackupLogErro__b>();

global Database.QueryLocator start(Database.BatchableContext objContext) {
    system.debug('opa');
    String query = 'SELECT Id, Classe__c, Criticidade__c, Descricao__c, ' +
                   'EquipeResponsavel__c, ExportarRegistro__c, Funcionalidade__c, ' +
                   'Metodo__c, TipoErro__c FROM LogErro__c WHERE ' + 
                   'CreatedDate <= LAST_N_DAYS:' + DAYS_AGO;
    return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext objContext, List<LogErro__c> lstErrorLog){
    system.debug('lstErrorLog = ' + lstErrorLog);
    if(lstErrorLog.size() > 0){ 
        
        for(LogErro__c log : lstErrorLog){
            BackupLogErro__b bkpLog = new BackupLogErro__b();
            bkpLog.IdLogRemovido__c     = log.Id;
            bkpLog.Classe__c            = log.Classe__c;
            bkpLog.Criticidade__c       = log.Criticidade__c;
            bkpLog.Descricao__c         = log.Descricao__c;
            bkpLog.EquipeResponsavel__c = log.EquipeResponsavel__c;
            bkpLog.ExportarRegistro__c  = log.ExportarRegistro__c == true ? 'sim' : 'nao';
            bkpLog.Funcionalidade__c    = log.Funcionalidade__c;
            bkpLog.Metodo__c            = log.Metodo__c;
            bkpLog.TipoErro__c          = log.TipoErro__c;
            
            lstBkpLog.add(bkpLog);
        }
        
        if(lstBkpLog.size() > 0){
            List<Database.SaveResult> lstSaveResult = Database.insertImmediate(lstBkpLog);
            system.debug('lstSaveResult == ' + lstSaveResult);
        }
        
        try{
            delete lstErrorLog;
        }
        catch(Exception e){
            ILogError log = (ILogError)Type.forName('LogError').newInstance();
            log.systemDebugLogs(e, 'LogErrorBatch');
        }  
    }
}

global void execute(SchedulableContext ctx) {
    if(!Test.isRunningTest()){
        Id processId = Database.executeBatch(new LogErrorBatch());
        system.debug('[LogErrorBatch] Batch agendado : ' + processId);
    }
}   

global void finish(Database.BatchableContext objContext){ 
    system.debug('lstBkpLog == ' + lstBkpLog);       
}    
}
5
  • Not putting this as an answer, but there is a similar-ish issue here: trailblazer.salesforce.com/… - so try setting your api to less than 34 or to 51. Commented Apr 15, 2021 at 18:52
  • Hi. Which code is on line 43? Commented Apr 15, 2021 at 18:55
  • Was thinking that your ILogError could be trying to make a callout - so you have an exception and your logging is causing a further exception. But can't tell until you give a line number. Commented Apr 15, 2021 at 19:29
  • @CasparHarmer ILogError just have a system.debug code Commented Apr 15, 2021 at 19:42
  • @OlehBerehovskyi is the line with the code: List<Database.SaveResult> lstSaveResult = Database.insertImmediate(lstBkpLog); Commented Apr 15, 2021 at 20:15

0

You must log in to answer this question.

Browse other questions tagged .