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
Øyvind Borgersen 10Øyvind Borgersen 10 

CSV file upload skip line if field is blank


I've created a CSV file upload code, but need to enhance the code to skip the whole line if one field is blank.

For the code below I want to skip the line if csvRecordData[1]  is blank. 

csvAsString = csvFileBody.toString();
csvFileLines = csvAsString.split('\n');
for(Integer i=1;i<csvFileLines.size();i++){
Videogram_sales_number__c vidObj = new Videogram_sales_number__c();
//Create date as string
String dateFormatString = 'yyyy-MM-dd';
Date d =;
Datetime dt = Datetime.newInstance(d.year(), d.month(),;
String dateString = dt.format(dateFormatString);
//Split by comma or semicolon
string[] csvRecordData = csvFileLines[i].split(',|\\;');
if(csvRecordData[1] != null){
vidObj.Case_ID__c = csvRecordData[0];
vidObj.Number_of_copies__c = decimal.valueof(csvRecordData[1]);
vidObj.Registration_date__c =;
vidObj.RegistrationNumberDummy__c = dateString;
vidObj.Titledummy__c = csvRecordData[2];
vidObj.RegistrationNumberDummy__c = csvRecordData[3];