Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Writing CSV files using APEX

79 views

Published on

  • Login to see the comments

  • Be the first to like this

Writing CSV files using APEX

  1. 1. Writing CSV files using APEX
  2. 2. I had a requirementto send a file with single record as a CSV attachment public static void xxxx (List<String> CIDS) { try { List<Case> Caselist= [Select <Fields> from Case where ID in :CIDS]; == Selectdesired fields from table === Form Header String ===== string header1 = 'Account Type,DUNS#,Complaint Incident Closed,Customer FirstName n'; string header = header1 ; string finalstr = header ; =====Form Data string concatenated with “,’ for(Case a: Caselist ) { string recordString0 =a.Account_Type__c+','+a.Account_DUN_Number__c+','+a.Status+','+a.Contact_First_Nam e__c'+'n'; string recordstring = recordString0 ; finalstr = finalstr +recordString; } Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment(); blob csvBlob = Blob.valueOf(finalstr); string csvname= 'CaseQA.csv'; csvAttc.setFileName(csvname); csvAttc.setBody(csvBlob); // Email process Write code to email file

×