What is the best way to get the number of childrecords on a personaccount with the PersonContactId as Id field, the lookup being a contact lookup?
I have the object Newsletter, with a contact lookup field and want a SOQL which gives me personaccounts with the number of related newsletter.
I tried:
[SELECT ID, PersonContactId, (SELECT Id FROM Newsletter__r) FROM Account]
, but it only tells me that it doesnt understand the relationship.
I also tried getting the it with a separate SOQL:
[SELECT Id, count(Id) FROM Newsletter__c WHERE ContactId__c in :setPersonAccounts]
, but I get the error "Field must be grouped or aggregated: Id" and if I group by id I get the error "Grouped field should not be aggregated: Id".