1

I am trying to create a csv attachment through apex, I am getting the csv with the values. But some values for eg. 'Hi I am xyz.
\n This is an example code.
' are getting split to next cell because of the escape sequence '\n' in the value itself. Is there any way to skip the break and next line html escape tags??

    if(attList != null && attList.size()>0){
    for(Attribute__c att : attList)
    {
        if(rows != null){
            rows = rows + att.Name +',';
            rows = rows+ att.Value__c+',';      
        }
        rows = rows + '\n';
    }
}
if(rows == null){
    rows = '';
}

if(csvFileData != null){
    csvFileData += rows;
}else{
    csvFileData = headerName + '\n' + rows;
}
csvFileData = csvFileData.replace('null','');
DateTime currenttime = DateTime.now();
String strConvertedDate = currenttime.format('dd/MM/yyyy HH:mm:ss', 'Australia/Sydney');
String fileName = 'Attribute list' + ' ' +strConvertedDate+'.csv';
Attachment attach = new Attachment();
attach.Body = Blob.valueof(csvFileData);
attach.Name = fileName;
attach.ParentID = pc.Id;
attachmentList.add(attach);
system.debug('attachmentList-->'+attachmentList.size());

if(!attachmentList.isEmpty()){
    database.insert(attachmentList, true);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.