function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jannu SairamJannu Sairam 

I want to get a list of records for an object based on input field(created date) as a pdf from vf page

Best Answer chosen by Jannu Sairam
SwethaSwetha (Salesforce Developers) 
HI Jannu,
Try the below code which is in the context of the account object. You can customize the code as per your requirement
<apex:page controller="AccountController" docType="html-5.0" renderAs="{!render}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:input label="Start Date" value="{!startdate}" type="date" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!search}" value="Search" />
                  <apex:commandButton value="download pdf" action="{!Downloadhere}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!accounts}" var="acc">
                <apex:column value="{!acc.Name}" />
                <apex:column value="{!acc.CreatedDate}" />              
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class AccountController {
    public Date startDate { get; set; }
    public string render {get; set;}
    public Date endDate { get; set; }
    public List<Account> accounts { get; set; }
    public void Downloadhere(){
        render='pdf';
    }
    
    public void search() {
       
        accounts = [SELECT Id, Name, CreatedDate 
                    FROM Account 
                    WHERE CreatedDate >= :startDate ];
       
}
}

If this information helps, please mark the answer as best. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Jannu,
Try the below code which is in the context of the account object. You can customize the code as per your requirement
<apex:page controller="AccountController" docType="html-5.0" renderAs="{!render}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:input label="Start Date" value="{!startdate}" type="date" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!search}" value="Search" />
                  <apex:commandButton value="download pdf" action="{!Downloadhere}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!accounts}" var="acc">
                <apex:column value="{!acc.Name}" />
                <apex:column value="{!acc.CreatedDate}" />              
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class AccountController {
    public Date startDate { get; set; }
    public string render {get; set;}
    public Date endDate { get; set; }
    public List<Account> accounts { get; set; }
    public void Downloadhere(){
        render='pdf';
    }
    
    public void search() {
       
        accounts = [SELECT Id, Name, CreatedDate 
                    FROM Account 
                    WHERE CreatedDate >= :startDate ];
       
}
}

If this information helps, please mark the answer as best. Thank you
This was selected as the best answer
Jannu SairamJannu Sairam
Thanks Swetha  ,
but i want that data to be dispalyed in tabular format