+ Start a Discussion
laytro1978laytro1978 

Apex search to return dates

Hi,

 

I would like to build a VF page which pulls back a list of all opportunities with a certain close date.

 

Are there any good guides or starter code.

 

Simple VF page with a date search box, it search and it pulls back the opportunities.

 

Thanks

 

R

Best Answer chosen by Admin (Salesforce Developers) 
laytro1978laytro1978

Thanks for the help, solution below

 

 

<apex:page standardController="Reservation__c"  extensions="Resmanager">
    <apex:form >
        <apex:sectionHeader title="Availability Search"/>            
            <apex:pageBlock title="Search">
                <apex:pageBlockButtons >
                    <apex:commandButton action="{!reservation}" value="Search"/>
                </apex:pageBlockButtons>
                <apex:pageBlockSection columns="2">
                    <apex:inputField value="{!Reservation__c.Start_Date__c}"/>
                    <apex:inputField value="{!Reservation__c.End_Date__c}"/> 
                </apex:pageBlockSection>
            </apex:pageBlock>  
            <apex:pageBlock title="Reservations">
                <apex:pageBlockSection >
                    <apex:pageBlockTable value="{!Reservations}" var="res">
                        <apex:column value="{!res.Name}"  />
                        <apex:column value="{!res.Start_Date__c}"  />
                        <apex:column value="{!res.End_Date__c}"  />
                        <apex:column value="{!res.Nights__c}"  />
                        <apex:column value="{!res.Status__c}"  />
                        <apex:column value="{!res.Reservation_Contact__c}"  />
                    </apex:pageBlockTable>
                </apex:pageBlockSection>   
            </apex:pageBlock> 
    </apex:form>
</apex:page>

 

 

Public class Resmanager {

    public PageReference reservation() {
        return null;
    }

    public Reservation__c reservation {get;set;}
    public Resmanager(ApexPages.StandardController controller) {
           reservation=(Reservation__c)controller.getRecord();
             }
            
    public List<Reservation__c> getReservations(){
            List<Reservation__c> listBd=[select Id, Name, Start_Date__c, End_Date__c, Nights__c, Status__c, Reservation_Contact__c from Reservation__c r 
                where  (Start_Date__c >= :reservation.Start_Date__c 
                    and 
                    Start_Date__c <= :reservation.End_Date__c
                    )
                    or
                    (End_Date__c >= :reservation.Start_Date__c
                    and
                    End_Date__c <= :reservation.End_Date__c)];  
            return listBd;   
        }
}

 

 

 

 

 

All Answers

Ritesh AswaneyRitesh Aswaney

Not sure if you've come across the Page Developers Guide, but here's a link

http://www.salesforce.com/us/developer/docs/pages/salesforce_pages_developers_guide.pdf

 

I would say thats the best place for you to start.

 

Not completely sure of your requirement, but it also seems like something you can do with List Views and Filters - these are just standard config as opposed to custom code, which you are considering. Read up on List Views, and you could surprise youself !

 

If indeed your requirement is so complex as to solicit customisation, then it would seem like you need a simple VF Page bound to a Controller Extension (Extending the Opportunity Standard Controller).

Laytro80Laytro80

Hi,

 

Thanks for this.

 

I am actually looking to build a more complicated list view using an extension controller.

 

Wanted to see how others have built a list view custom controller to control dates as I have a few upcoming projects that revolve around this solution.

 

I can find text based search / list but not date.

 

Thanks

laytro1978laytro1978

Thanks for the help, solution below

 

 

<apex:page standardController="Reservation__c"  extensions="Resmanager">
    <apex:form >
        <apex:sectionHeader title="Availability Search"/>            
            <apex:pageBlock title="Search">
                <apex:pageBlockButtons >
                    <apex:commandButton action="{!reservation}" value="Search"/>
                </apex:pageBlockButtons>
                <apex:pageBlockSection columns="2">
                    <apex:inputField value="{!Reservation__c.Start_Date__c}"/>
                    <apex:inputField value="{!Reservation__c.End_Date__c}"/> 
                </apex:pageBlockSection>
            </apex:pageBlock>  
            <apex:pageBlock title="Reservations">
                <apex:pageBlockSection >
                    <apex:pageBlockTable value="{!Reservations}" var="res">
                        <apex:column value="{!res.Name}"  />
                        <apex:column value="{!res.Start_Date__c}"  />
                        <apex:column value="{!res.End_Date__c}"  />
                        <apex:column value="{!res.Nights__c}"  />
                        <apex:column value="{!res.Status__c}"  />
                        <apex:column value="{!res.Reservation_Contact__c}"  />
                    </apex:pageBlockTable>
                </apex:pageBlockSection>   
            </apex:pageBlock> 
    </apex:form>
</apex:page>

 

 

Public class Resmanager {

    public PageReference reservation() {
        return null;
    }

    public Reservation__c reservation {get;set;}
    public Resmanager(ApexPages.StandardController controller) {
           reservation=(Reservation__c)controller.getRecord();
             }
            
    public List<Reservation__c> getReservations(){
            List<Reservation__c> listBd=[select Id, Name, Start_Date__c, End_Date__c, Nights__c, Status__c, Reservation_Contact__c from Reservation__c r 
                where  (Start_Date__c >= :reservation.Start_Date__c 
                    and 
                    Start_Date__c <= :reservation.End_Date__c
                    )
                    or
                    (End_Date__c >= :reservation.Start_Date__c
                    and
                    End_Date__c <= :reservation.End_Date__c)];  
            return listBd;   
        }
}

 

 

 

 

 

This was selected as the best answer