Visualforce page:

<apex:page controller="MyControlleremployee" tabStyle="employee__c">

<apex:form >
  <apex:pageBlock id="blockId" title="Employee Details">
    <apex:pageblocktable value="{!myemployees}" var="emp">
         <apex:column >
         <apex:facet name="header">{!$ObjectType.employee__c.fields.name.label}</apex:facet>
             <apex:inputField value="{!emp.name}" rendered="{!tobeEdited == emp.id}"/>
             <apex:outputField value="{!emp.name}"  rendered="{!!(tobeEdited == emp.id)}"/>
         <apex:column >
         <apex:facet name="header">{!$ObjectType.employee__c.fields.email__c.label}</apex:facet>
             <apex:inputField value="{!emp.email__c}"  rendered="{!tobeEdited == emp.id}"/>
             <apex:outputField value="{!emp.email__c}"   rendered="{!!(tobeEdited == emp.id)}"/>             
         <apex:column >
         <apex:facet name="header">{!$ObjectType.employee__c.fields.max_pay__c.label}</apex:facet>
             <apex:inputField value="{!emp.max_pay__c}"  rendered="{!tobeEdited == emp.id}"/>
             <apex:outputField value="{!emp.max_pay__c}"   rendered="{!!(tobeEdited == emp.id)}"/>             
         <apex:column >
         <apex:facet name="header">{!$ObjectType.employee__c.fields.min_pay__c.label}</apex:facet>
             <apex:inputField value="{!emp.min_pay__c}"  rendered="{!tobeEdited == emp.id}"/>
             <apex:outputField value="{!emp.min_pay__c}"   rendered="{!!(tobeEdited == emp.id)}"/>             
         <apex:column >
              <apex:commandbutton value="Edit" rerender="blockId" rendered="{!!(tobeEdited == emp.id)}" >
                  <apex:param assignTo="{!tobeEdited}" value="{!emp.id}" name="ittobeedited"/>
                <apex:commandbutton value="save" rerender="blockId" rendered="{!!(tobeEdited == emp.id)}" />
              <apex:commandButton value="save" action="{!saveRecord}" reRender="blockId" rendered="{!tobeEdited == emp.id}"/>
               <apex:commandButton action="{!Deleted}" value="Deleted" />
                   <apex:commandButton action="{!Download}" value="Download"/>

Apex class :

public class MyControlleremployee {

    public PageReference Download() {
       return null;

    public List<employee__c> myemployees;
    public id tobeEdited{get; set;}     

    public MyControlleremployee(){


    public List<employee__c> getMyemployees(){
        myemployees = [select Id,name,email__c,max_pay__c,min_pay__c from employee__c WHERE (owner.id =: userinfo.getuserid()) limit 10];            
        return myemployees;           
 public void saveRecord(){
        employee__c tobeupdated;
        for(employee__c temp:myemployees){
                tobeupdated = temp;   
        update tobeupdated;
        tobeEdited = null;
    public void Deleted(){
    employee__c tobedeleted;
    for(employee__c tmp:myemployees){
    tobedeleted = tmp;
    delete tobedeleted;
    tobedeleted = null;

  • What is the problem ? Can you provide not only code but some informations please ?
    – SF_user
    Jan 6, 2015 at 9:19

1 Answer 1


In order to get a download to Excel, you can create a (new) visualforce page and render and immediately download it as excel (contentType="application/x-excel#RenderAsTestFile.xls"), also pointed out here:


So you need to make sure that the download button opens a new page (pageReference) with the selected record in e.g. a pageBlockTable. Then add the contentType above to that new page and it will immediately start downloading the Excelfile with the selected record.

  • You need to make sure that the details of the selected record are put in a new (list of) employees: the one that you use in the new page. That can be done in various ways. But I'd need to see the complete updated controller and the VF page to see what's wrong. Jan 6, 2015 at 12:23
  • You could use apex:param the same way as you did for the edit button and use the stored id to construct the url in the new PageReference. Then in the new page, use the id to fetch the record and put it on the page. Jan 6, 2015 at 12:31
  • I don't have the code. If you update your question with the current code you have I can have a look and see what's still wrong Jan 6, 2015 at 13:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .