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
JoshTonksJoshTonks 

Querying Opps Count With Events That Are Sat On Appointment

Hi,

Im having alot of difficulty with this some Apex Code

Im trying to Query Opportunities that are Opp Enquiry Source contains referrals and the event on it is a Sat On Appointment. So i can get a count of them in visualforce.

I know how to display counts in visualforce, I know how to query singular objects for these results but because of the information is on an event and some is on an opportunity I have come to a sticking point.

I thought i might have been able to do this with I was previously advised to do it via this
What.Opp_Enquiry_Source LIKe :IsRef
However this doesnt work and comes up with 

No such column 'Opp_Enquiry_Source__c' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. Is this because of how the What field works on events. That field defiantly exists ive used it previously but its not working

I thought maybe this the following would work 
return [SELECT Count()
            FROM Opportunity o,o.Event e
WHERE o.Opp_Enquiry_Source__c LIKe :IsRef AND e.Sat_On__c = TRUE
Ive tried this both ways so Event e, e.Opportunity o and Opportunity o,o.Event e

I get this as error 

Didn't understand relationship 'e.Opportunity' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Thank you in advance


 
Best Answer chosen by JoshTonks
Dayakar.DDayakar.D
Hi Tonks,

Try below query.
 
select count(id) from event where Sat_On__c = TRUE
 AND whatId IN (Select id from Opportunity where xxxx)

Best Regards,
Dayakar.D