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
k sfdck sfdc 

URGENT:Based on picklist( date and month) how to display my object records Dynamically?

My page:
------------
<apex:page controller="MonthYearpicklistcontroller">
  <apex:form >
  <apex:pageBlock >
  <apex:selectList size="1" value="{!myDateRange}">
     <apex:selectOptions value="{!DateRangeOptions}"/>
     <apex:actionSupport event="onchange" reRender="out1"/>
</apex:selectList>
<apex:commandButton value="Go" action="{!doAction}" />
<apex:pageBlockSection rendered="{!isBoolean}">
          <ul>
        <apex:outputLabel value="Account:">
        <apex:repeat value="{!accounts}" var="account">
       
            <li>
                {!account.Name}
               
                <ul>
                <apex:outputLabel value="Opportunity:">
                <apex:repeat value="{!account.children}" var="opportunity">
                    <li>
                        {!opportunity.Name}
                        
                        <ul>
                        <apex:outputLabel value="Contact:">
                        <apex:repeat value="{!opportunity.children}" var="contact">
                            <li>
                                {!contact.Name}
                            </li>
                        </apex:repeat>
                        </apex:outputLabel>
                        </ul>
                        
                    </li>
                </apex:repeat>
                </apex:outputLabel>
                </ul>
                
            </li>
        </apex:repeat>
        </apex:outputLabel>
        </ul>
       

</apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

My Controller:
----------------

public class MonthYearpicklistcontroller {
    public Boolean isBoolean { get; set; }
    public String myDateRange { get; set; }
   
    public List<SelectOption> getDateRangeOptions() {

        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('1-2014','Jan-2014'));
        options.add(new SelectOption('2-2014','Feb-2014'));
        options.add(new SelectOption('3-2014','Mar-2014')); `enter code here`
        options.add(new SelectOption('4-2014','Apr-2014'));
        options.add(new SelectOption('5-2014','May-2014'));
        options.add(new SelectOption('6-2014','june-2014'));
        options.add(new SelectOption('7-2014','july-2014')); 
        options.add(new SelectOption('8-2014','Aug-2014'));
        options.add(new SelectOption('9-2014','Sep-2014'));
        options.add(new SelectOption('10-2014','Oct-2014'));
           return options; 
    }
     public List<Wrapper> accounts{
        get
        {
         
       
            List<Wrapper> accounts = new List<Wrapper>();
            List<Id> oppIds = new List<Id>();
            for(Account acc : [Select Id, Name, (Select Id, Name From Opportunities) From Account])
            {
                Wrapper account = new Wrapper();
                account.Id = acc.Id;
                account.Name = acc.Name;
                account.children = new List<Wrapper>();
                accounts.add(account);
                for(Opportunity opp : acc.Opportunities)
                {
                    Wrapper opportunity = new Wrapper();
                    opportunity.Id = opp.Id;
                    opportunity.Name = opp.Name;
                    opportunity.children = new List<Wrapper>();
                    account.children.add(opportunity);
                    oppIds.add(opp.Id);
                }
            }
            Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>([Select Id, (Select Id, Contact.Name From OpportunityContactRoles) From Opportunity where id In :oppIds]);
            for(Wrapper account : accounts)
            {
                for(Wrapper opportunity : account.children)
                {
                    for(OpportunityContactRole opCR : oppMap.get(opportunity.Id).OpportunityContactRoles)
                    {
                        Wrapper contact = new Wrapper();
                        contact.Id = opCR.Id;
                        contact.Name = opCr.Contact.Name;
                        opportunity.children.add(contact);
                    }
                }
            }
            return accounts;
        }
    }
   
   
     public PageReference doAction() {
     isBoolean =true;
        return null;
    }
   
     public class Wrapper{
        public Id Id{get;set;}
        public String Name{get;set;}
        public List<Wrapper> children{get;set;}
    }

}

How to display based on picklist month and date related records?

please help me......
Mohammed HaseebMohammed Haseeb
HI - you need to do some thing like this:

I presume you want to display the recrods of account for the month and the year the user has selected. 

So when the user selects the date and clicks the "GO" command button the result will get updated. 

remove this below line of code:
<apex:actionSupport event="onchange" reRender="out1"/>

So now update your query so that it has the ability to select only records for the date selected by the user:

Account acc : [Select Id, Name, (Select Id, Name From Opportunities) From Account Where CreatedDate=:myDaterange]

Your date format whcih you gave given above in the code will not work if you use it in query you may have to supply the correct date format check the salesforce date formats the standard one is YYYY-MM-DD and if its DateTime field it will be YYYY-MM-DDTHH:MM:SSz. Make sure you check the parametre is not null before the query and you either assign default value as today if the field is null or you could have two query one working when the fiels has a value.