anusha(salesforce developer)

Wednesday, 14 September 2016

How to download visualforce page as text file in Salesforce?

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:

No comments:

Post a Comment