From 7f9a2b2f918f4c1beaa63c18c867b888ec82ddbd Mon Sep 17 00:00:00 2001 From: Sankaran Nepolean Date: Fri, 22 Feb 2019 06:49:20 +0000 Subject: [PATCH] Update CSVFileUtil.cls This fix is to support empty values at the end of csv file rows. --- custom_md_loader/classes/CSVFileUtil.cls | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_md_loader/classes/CSVFileUtil.cls b/custom_md_loader/classes/CSVFileUtil.cls index d99cbd5..843ec2f 100644 --- a/custom_md_loader/classes/CSVFileUtil.cls +++ b/custom_md_loader/classes/CSVFileUtil.cls @@ -42,7 +42,10 @@ public class CSVFileUtil { // check for blank CSV lines (only commas) if (line.replaceAll(',','').trim().length() == 0) break; - List fields = line.split(','); + // -1 in the split method will not remove empty values at the end in the result list. + // For example, if a csv file line has A,B,, -> The result of this split would be + // ['A', 'B', '', '']. Withouth -1 in the method it would be ['A', 'B'] + List fields = line.split(',', -1); List cleanFields = new List(); String compositeField; Boolean makeCompositeField = false;