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
AK_SmithAK_Smith 

Show on VF page results of the 3 SOQL requests

Hello! 
I need to show on the VF page (table) results of the 3 SOQL requests:

I have 2 objects: Users and related SyncLog__c

I need to see on the table
First column: Users list
Second column: Is there records created before 10 AM YES/NO
Third column: Is there records created after 6 PM YES/NO



 
Raj R.Raj R.
For the second and third column, is that criteria for today only or should that include all time? For example, do you need all user records created before 10AM since 2 years ago or do you need all user records created before 10AM today?

With out more details,
 
Datetime todayBeforeTen = Date.Today();
todayBeforeTen = todayBeforeTen.addHours(10);

Datetime todayAfterSix = Date.Today();
todayAfterSix = todayAfterSix.addHours(18);

// Create maps to make it easier to fetch
Map<Id,User> usersBeforeTen = new Map<Id,User>();
Map<Id, User> usersAfterSix = new Map<Id,User>();

for(User usr : [Select Name, CreatedDate
                From User]) {
  if(usr.CreatedDate < todayBeforeTen) {
    usersBeforeTen.put(usr.id, usr);
  }
  else if(usr.CreatedDate > todayAfterSix) {
    usersAfterSix.put(usr.id, usr);
  }
}//end for
Now that we have the maps, you can use the following to print them as needed. 
<apex:pageblocktable value=”{!MapName} var=”key”>

<apex:column value=”{!MapName[key].< Enter value regarding this key here>}”/>

</apex:pageblocktable>

Other resources:
  • http://bobbuzzard.blogspot.com/2011/03/visualforce-dynamic-map-bindings.html
  • https://developer.salesforce.com/forums/?id=9060G000000UYlqQAG (using <apex:repeat>)
  • https://salesforce.stackexchange.com/questions/46461/how-can-i-display-the-key-value-from-a-map-in-a-vf-page