You need to sign in to do that
Don't have an account?
Pankaj_Ganwani
Removing html numbers from csv created using apex
Hi All,
When we are creating csv file using apex code, I am getting html number corresponding to the special symbol(',','''). I have mentioned my code below:
I am getting '''(html number of single quote) instead of single quote in received file. Please let me know how to fix this.
Thanks,
Pankaj
When we are creating csv file using apex code, I am getting html number corresponding to the special symbol(',','''). I have mentioned my code below:
PANG__Child_Object__c obj = [SELECT Id, PANG__test_rich__c from PANG__Child_Object__c where Id =: 'a0K28000006bqaA']; string recordString = '"'+obj.id+'","'+obj.PANG__test_rich__c.replaceAll('\\<[^\\>]*\\>',' ')+'"'; //recordString = recordString.escapeEcmaScript(); Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment(); blob csvBlob = Blob.valueOf(recordString); string csvname= 'Account.csv'; csvAttc.setFileName(csvname); csvAttc.setBody(csvBlob); csvAttc.setContentType('text/csv'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(new List<String>{'email'}); mail.setSubject('test'); mail.setcharset('UTF-8'); mail.setHtmlBody('find attachment'); mail.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc}); Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{mail});
I am getting '''(html number of single quote) instead of single quote in received file. Please let me know how to fix this.
Thanks,
Pankaj
Please use this below code. Write a regular expression if you have more characters like this for ease.
String recordString = '"'+obj.id+'","'+obj.PANG__test_rich__c.replaceAll('\\<[^\\>]*\\>',' ')+'"';
recordString = recordString.replace(''','\'');
System.debug('recordString'+recordString);
Let me know any help needed .