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
Yoshinori MoriYoshinori Mori 

Execute SOQL with selected date on the calender

Is there any method to execute SOQL with selected date on the calender?

As far as I understand, I should use action support tag and "on onclick" or "on chage" for event on visual force page.


I appreciate if you could help me with Apex code either..





onchange is what you are looking for, something like this:



<apex:inputField value="{!opportunity.CloseDate}">
 <apex:actionSupport event="onchange" rerender="IDOFBLOCKTORERENDER" status="status"/>




Yoshinori MoriYoshinori Mori

Thank you for the reply.

Could it be possible to let me know how the selected date sent to SOQL call method as a parameter and run in SOQL.

Is there any utility method like "=Date.selected( )" ?




You use a "binding" (think of an inline placeholder, much like a SQL variable) in order to pass it directly into the query statement. For example, you might do this:



public class someController {
  // ... 

  // member variable called opportunity is used for a date input field.
  public Opportunity anOpp { get; set; }

// Later, in a function, we might bind to this directly.
  public void someFunction() {
    // ...
    List<Opportunity> records = [select id,name,closedate,amount,stagename from opportunity where closedate = :anOpp.closedate];
    // ...
  // ...


Literally, all you have to do is bind to it by using a colon ":" character followed by the name of the variable as it exists in your controller.

Yoshinori MoriYoshinori Mori

Thank you for the addtional info.


According to a message posted and titled "pass selected date value to controller" by other contributor. he asked with example as below.(It seemds like there was no reply to it.)

Calling another DBAAccess class from the controller below  to pass "actyvitydate" on the calender as a parameter can query records which have matched-dates with the activitydate?  

Does this also work?



         Task t = new Task();
         public Date selecteddate = t.activitydate;
         public Task getTask() { return t; }



          <apex:inputField value="{!task.activitydate}"/>




I don't think it would work the way you expect if you do it this way (there's no setter method, and the task is transient and not part of the view state; there's no way for the selected date to get back into the controller). Personally, I'd recommend that you have a public variable:



public Task Task { get; set; }

Which is then initialized in the constructor:


   Task = new Task();

You can do it however you'd like, so long as there is a setter method so that the value can get back into the controller.



Yoshinori MoriYoshinori Mori

Thank you so much for the additional info.

I'll try this.