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
Arjun y 7Arjun y 7 

How to add list of CSV values into single string

Hi All,

I am unable to combine the list of values into single string.

Below code gives output as:

Csvfilebody'29682
','92367
','72661
','14768
','15031
','1158'

I need output as:
Endpoint: Csvfilebody'29682','92367','72661','14768','15031','1158'
String uploadCsv = csvFileBody.toString().trim();
System.debug('Csvfilebody'+uploadCsv);
//uploadCsv:Csvfilebody29682
92367
72661
14768
15031
1158
 List<String> uploadCSVlist = new List<String>();
uploadCSVlist = uploadCsv.split('\n');
List<String> csvFieldNames = new List<String>();
 csvFieldNames = uploadCSVlist[0].split(',');
List<String> sme = new List<String>();
string allstring;
for(integer i=1;i<uploadCsvList.size();i++)
{
 allString = allString+','+'\''+uploadCSVlist[i]+'\'';
  }

 
Best Answer chosen by Arjun y 7
Jerome RussJerome Russ
Are you working with a file that uses \r\n for new lines? (generally Linux and MacOS) If the file was created natively in Salesforce it likely uses \r\n as well. If you aren't sure which new line character the file uses you can use a hex editor to find out or, an easier approach is to simply change the split to split on '\r\n' and see if it fixes the problem.

All Answers

Jerome RussJerome Russ
Are you working with a file that uses \r\n for new lines? (generally Linux and MacOS) If the file was created natively in Salesforce it likely uses \r\n as well. If you aren't sure which new line character the file uses you can use a hex editor to find out or, an easier approach is to simply change the split to split on '\r\n' and see if it fixes the problem.
This was selected as the best answer
Arjun y 7Arjun y 7
Hi Russ,

It worked for me. Thank You!!