0
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 1

5

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

2
  • There's at least 3 other problems with this code, too.
    – sfdcfox
    Commented Jan 8, 2020 at 4:33
  • ah yes -- before insert trigger referencing acct.Id being notable
    – cropredy
    Commented Jan 8, 2020 at 5:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .