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
Josephine ButJosephine But 

I am trying to query from relationship

Hi,
  I have an object appointments which have a lookup field to Hospital(Hospital__c) and I have an object Hospital which contains the names of the hospital. I want to know how many appointments in each hospital. What is the query look like?

Thanks,
    Jo
AshwiniAshwini (Salesforce Developers) 

Hi Josephine,
Can you elaborate more on the ask?

 

Arun Kumar 1141Arun Kumar 1141
Hi Josephine,

To know the number of appointments for eah hospital, the querry can be look like -
Select count(Id),Hospital__c from Appointment__c group by Hospital__c

If this helps you, please mark it as a best answer
Thanks!
 
Naresh Kaneriya 9Naresh Kaneriya 9

Hi Josephine,

 you can use a below SOQL query to achieve this 

SELECT Hospital__c, COUNT(Id) FROM Appointment__c GROUP BY Hospital__c

 

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks,
Naresh