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

How to download a csvBlob?

I have created a csvBlob that contains user records,

Can someone please tell me how to download that file?



Here is the code:


public with sharing class Send_noti_emails {

   public PageReference download_csv() {
         string header = 'Record Id, Name , First Name , Last Name , Email, Qulification\n';
         string finalstr = header ;
         string recordString;

  for (Inquery__c inquery: [SELECT Email__c,First_Name__c, Last_Name__c,Quilification__c FROM Inquery__c  WHERE Download__c = False]){

   recordString =','+inquery.First_Name__c+','+inquery.Last_Name__c+','+inquery.Email__c +','+inquery.Quilification__c +'\n';
   finalstr = finalstr +recordString;


    blob csvBlob = Blob.valueOf(finalstr);

   return null;




if you are not particular about Blob, here is an example of how to generate a .CSV file:




Yes i have done it this way before,

But i want a Bttn to call an APEX code,


I don't want it to be called in a VisualForce page,


It looks much more professional that way,


Thanks for your help,