I am trying to create an Apex Controller that outputs a list of event records. I would only like to print the oldest from each account where the Event is a meeting. After much thought I think the best way is to create a roll up summary on the Account record that shows the oldest date of all of the events. I then create a boolean variable in the Apex Controller that compares this field (Initial_Meeting_Date__c) with ActivityDate and use this in the WHERE clause.
public with sharing class initialMeeting {
public List<Event> finalList {get;set;}
public initialMeeting() {
List<Account> retrievedAccounts = [SELECT ID, Initial_Meeting_Date__c
FROM Account
WHERE Status__c = 'Active Prospect'];
Set<String> evt = new Set<String>();
for (Account accts : retrievedAccounts) {
evt.add(accts.ID);
}
Boolean dateCompare = true;
if(Account.Initial_Meeting_Date__c == Event.ActivityDate) {
dateCompare = true;
}
finalList = new List<Event> ();
finalList = [SELECT Id, AccountId, Subject, ActivityDate
FROM Event
WHERE type='Meeting' AND dateCompare='true'
AND AccountId IN :retrievedAccounts];
}
public List<Event> getUsersEvents() {
return finalList;
}
}
However Salesforce is giving me an error for dateCompare in the SOQL query.
Many thanks in advance for all your help.