How to download visualforce page as text file in Salesforce?

Sample Code:

Visualforce page:

<apex:page controller="Sample" sidebar="false" action="{!fetch}" contentType="text/plain/#emp.txt" 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];
    }   

}


Output:


2 comments:

  1. How can i write that .txt file from Salesforce to a Shared Document?
    Thank you in advance.

    ReplyDelete
    Replies
    1. Check this

      http://www.infallibletechie.com/2012/07/trigger-on-attachment-in-salesforce.html

      Cheers!!!

      Delete