3

apex program to create and download a file in a particular location

I want to save csv or xls files in a particular location in local

<apex:page controller="Sample" sidebar="false" action="{!fetch}" contentType="application/x-excel#account.xls" cache="false">
Employee Number : {!emp.Name}
Employee Name : {!emp.Employee_Name__c}
City : {!emp.City__c}
Email : {!emp.Email__c}
Description : {!emp.Description__c}
</apex:page>

Apex Controller:

public class Sample
{  
    public String empId;
    public Employee__c emp {get;set;}

    public Sample()
    {

    }

    public void fetch()
    {
        empId = Apexpages.currentpage().getparameters().get('eid');
        emp = [SELECT Name, Employee_Name__c, City__c, State__c, Email__c, Description__c FROM Employee__c WHERE ID =: empId];
    }   

}

But i want to save directly in my hard disk in a certain location or server in a certain location how we can do it??

1
  • Hi, would you mind trying to find a few tags which are more specificly related to the subject of your question ? You could for instance edit your question to remove the salesforce-crm tag and add the Apex tag. Dec 24, 2013 at 17:26

2 Answers 2

7

You can't control the browser's save location. That is up to the user to select. An alternative could be to use something on the local computer such as Jitterbit Data Loader to query the data from Salesforce and have it save locally. These tools allow you to schedule them to run at certain times.

1

You cannot do this directly. However, when the user is directed to this page, the browser will automatically show the dialog to download the file.

You might want to look at the contentType value. It should be 'application/vnd.ms-excel#Account.xls'.

Check out this blog post on how to do this.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.