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
Vigneshwaran LoganathanVigneshwaran Loganathan 

Return batch class execute values to Apex class

I am importing large csv using VF page. Before importing I need to Validate the data. So, I have created a validate method which reads the file and stores in a list(and do validations further). Since the file has nearly >5k records it hits CPU Time limit exception. So, i thought of passing the parsedValues to batch class and get sObject values. Below is the method i have in class,


I need to pass ParsedVal to batch class and return results to Normal class to proceed checking further methods.
Class : SPLImortGildExt
Public list<sObject> csv2sObject(list<List<string>> parsedval)
    { 
      splitObject = selectedObj.split(',');  
       SPL_BatchCsv2sObject sb = new SPL_BatchCsv2sObject(parsedval);
        Database.executeBatch(sb,200);

      return sObj; // Need to get value from Batch apex
   }
 
Batch Apex :

global void execute(Database.BatchableContext context, SObject[] records)
          list<sobject> sObj = new list<sobject>();
       
          Schema.sObjectType objectDef = Schema.getGlobalDescribe().get(splitObject[0]).getDescribe().getSObjectType();
                       
          for(list<string> head : parsedVal)
          {
            for(string col : head)
            {
             if(headerMap.containsKey(col.Trim()))
              headers.add(headerMap.get(col.Trim()));
             else
              headers.add(col);
             }
            break;
          }
            
          integer rowNum = 0; 
          
          for(list<string> row : parsedval)
          {
            if(rowNum == 0)
            {
              rowNum++; 
              continue;
            }
            
            else
            {
              sObject thisObj = objectDef.NewsObject();
                           
              integer col = 0;
              
              for(string colx : row)
              {
               
                string headerName = headers[col].trim();
                
                
                Try
                {
                       if((colx.contains('/')  || colx.contains('-'))
                      {
                      
                       datex =  (colx.contains('/')) ? colx.split('/') : colx.split('-');
                       
                         thisObj.put(headerName , Tempdate);                       
                      }
                      
                      else
                      {
                          if(headerName=='active_vod__c') 
                          {
                              thisObj.put(headerName , boolean.valueof(colx));
                          }
                          
                         
                      }

                    }
                                                 
                     col++;
                  }  // closing column for loop
                
              
              sObj.add(thisObj);  // Need to pass this values to previous class 
                
              
              rowNum++;
              } //close else
            } // close for         
        }
  
    }
Is there a way to acheive this.? 

Thanks.!