trigger AccountCallableContact on Account (before insert) {
for (Account acct : Trigger.new) {
if (acct.Phone != Null) {
LIST<Contact> MatchContact = [SELECT AccountId,
COUNT(Id)
FROM Contact
WHERE Id = :acct.Id
AND Phone != NULL
GROUP BY AccountId];
}
}
}
1 Answer
The GROUP BY makes the SOQL an aggregate query and the result must be a List<AggregateResult>
See Apex doc on Aggregate queries
That said, your trigger is not bulkified as you are doing SOQL inside of a for loop. See Trailhead on how to avoid this
-
-
ah yes -- before insert trigger referencing acct.Id being notable– cropredyCommented Jan 8, 2020 at 5:53