• Krishna_Beginner
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Here is the code I am facing performance issue with. My code is working for 500 records with 100 in each batch. I am trying to process the same csv file with 1000+ records with a batch size of 500 and getting "Time limit exceeded" error on visualforce page. We have a requirment to scale this up to 100,000 thousand records or at least to 50,000 records. I have provided only standard fields in the below code. We have totally 32 columns in the csv file that we are uploading through visualforce page UI. A quick help is much appreciated!!!

public void importCSVFile(){
            csvAsString = csvFileBody.toString();
            csvFileLines = csvAsString.split('\n');
            Integer recordCount = csvFileLines.size();
            Integer batchSize = 500;
            Double batchCount = Math.ceil(recordCount/batchSize);
            System.debug('Batch Counts : '+ batchCount);
       try{
            for( Integer i=1; i<=batchCount; i++){
                recordbatch = recordbatch = new List<String>();
                acclist.clear();
                for(Integer j=(i-1)*batchSize+1; j<=(i*batchSize); j++){
                 System.debug('Record Count : '+ j);
                    if(csvFileLines[j] != null){
               
                    Account account = new Account();
                    string[] csvRecordData = csvFileLines[j].split(',');
                    account.Salutation = csvRecordData[7];
                    account.FirstName = csvRecordData[8];
                    account.LastName = csvRecordData[9];
                    account.PersonMailingCountry = csvRecordData[12];
                    account.PersonMailingStreet = csvRecordData[13];
                    account.PersonMailingCity = csvRecordData[14];
                    account.PersonMailingState = csvRecordData[15];
                    account.PersonMailingPostalCode = csvRecordData[16];
                       
                   acclist.add(account);  
              
               }else{
                        break;
                    }
                    System.debug('Batch size executed : '+ j);
               }
                insert acclist;
               
            }
            }catch (Exception e)
            {
                ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'Please make sure input csv file is correct'+e);
                ApexPages.addMessage(errorMessage);
                System.debug('Exception: '+ e);
            }
                   
  }
Here is the code I am facing performance issue with. My code is working for 500 records with 100 in each batch. I am trying to process the same csv file with 1000+ records with a batch size of 500 and getting "Time limit exceeded" error on visualforce page. We have a requirment to scale this up to 100,000 thousand records or at least to 50,000 records. I have provided only standard fields in the below code. We have totally 32 columns in the csv file that we are uploading through visualforce page UI. A quick help is much appreciated!!!

public void importCSVFile(){
            csvAsString = csvFileBody.toString();
            csvFileLines = csvAsString.split('\n');
            Integer recordCount = csvFileLines.size();
            Integer batchSize = 500;
            Double batchCount = Math.ceil(recordCount/batchSize);
            System.debug('Batch Counts : '+ batchCount);
       try{
            for( Integer i=1; i<=batchCount; i++){
                recordbatch = recordbatch = new List<String>();
                acclist.clear();
                for(Integer j=(i-1)*batchSize+1; j<=(i*batchSize); j++){
                 System.debug('Record Count : '+ j);
                    if(csvFileLines[j] != null){
               
                    Account account = new Account();
                    string[] csvRecordData = csvFileLines[j].split(',');
                    account.Salutation = csvRecordData[7];
                    account.FirstName = csvRecordData[8];
                    account.LastName = csvRecordData[9];
                    account.PersonMailingCountry = csvRecordData[12];
                    account.PersonMailingStreet = csvRecordData[13];
                    account.PersonMailingCity = csvRecordData[14];
                    account.PersonMailingState = csvRecordData[15];
                    account.PersonMailingPostalCode = csvRecordData[16];
                       
                   acclist.add(account);  
              
               }else{
                        break;
                    }
                    System.debug('Batch size executed : '+ j);
               }
                insert acclist;
               
            }
            }catch (Exception e)
            {
                ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'Please make sure input csv file is correct'+e);
                ApexPages.addMessage(errorMessage);
                System.debug('Exception: '+ e);
            }
                   
  }