Tuesday, October 13, 2015

Download csv File using Visual force page

I tried downloading a csv file from a visualforce page.

In the code below i am querying contacts object and downloading the query result in csv


 {!a.FirstName},{!a.lastName}


Apex Class:
public class Sample
{   
    public List contacts {get;set;}
    public pageReference fetch()
    {
         contacts = [SELECT Id,firstname,lastname FROM Contact limit 20];
        return null;
    }    
}

1 comment:

  1. contenttype="text/plain/#contacts.csv" its not working

    ReplyDelete