0

I am trying to create a CSV in the batch.

global void finish(Database.BatchableContext BC)
{
    for(ID a: temp)
    {
        String recordString = '"'+a+'"\n';
        finalstring = finalstring + recordString;
    }
    Blob csvBlob = Blob.valueOf(finalstring);
}

I'm able to form the CSV file, but the first record has extra characters added to the value like this:

null"001R000001dasdsadU"

I'm sure recordString has issues. How should I escape in a string?

cropredy
  • 71,240
  • 8
  • 120
  • 270
MnZ
  • 3,170
  • 10
  • 50
  • 99
  • 1
    You need to define finalString as a empty string and then check. String defineString = ''; – Devendra Sep 19 '16 at 11:26
  • Um. What are you trying to do? What is the problem? I find your question very difficult to follow. – Adrian Larson Sep 19 '16 at 11:43
  • 2
    @Devendra Thanks, your solution helped! I missed that out! Please add it as an answer. – MnZ Sep 19 '16 at 12:02
  • @AdrianLarson My batch class deletes records and emails a csv file of the record Ids. When I open the csv file, the first record would show as .. https://s4.postimg.io/b9wrg3zd9/9_19_2016_5_34_38_PM.png . It was a minor issue which devendra already answered. Sorry I couldn't be clear enough :( – MnZ Sep 19 '16 at 12:08

1 Answers1

2

First, you need to initialize finalString.

It would be,

String defineString = '';
Devendra
  • 5,075
  • 1
  • 24
  • 28