Issue on uploading CSV file with a column

Gianna: 5 days ago

I am uploading CSV file using email service functionality of salesforce.

Scenario 1) When I try to upload a file without comma in any column, It gets uploaded without any error.

Scenario 2) When I try to upload a file with comma present inside column, It copies the data to the next column because of commas.

The error is coming on column no 9:

Apex Class Snippet:

if (csvAsStringRowElement.size() > 0 && csvAsStringRowElement[9] != null && csvAsStringRowElement[9].trim().length() > 0) {
acc.PersonMailingStreet = csvAsStringRowElement[9].trim();

Carson: 5 days ago

Rough but if you have commas within your strings and they split improperly then you can replace the actual commas between columns with your own customer separator and split using that

String s = row.replace('","','*SEPERATOR*');
s = s.replace('"','');
String[] t = s.split('\\*SEPERATOR\\*');
return t;