1

To narrow down the problem - we have a method like this:

private static Object doSomeProcessing(List<AggregateResult> records) {
    ...
    // need to add additional logic here based on sobject type in records collection
    // e.g. if records are about Account, do this
    // else if records are about Contact, do that
    ...
}

Method takes collection of AggregateResult records as an input. And now we need to figure out somehow what actual sobject is behind this aggregated results inside this method to implement some additional business requirement. E.g. is it grouping of Accounts or Contacts or MyCustomObject__c etc.

Seems like the most straightforward way is to use getSobjectType for record or collection, but it just returns 'AggregateResult' and that's it, no actual sobject type.

Is there any trick to achieve this? Is it feasible at all? Any help would be appreciated.

P.S. We would like to avoid changing method signature to pass additional parameters.

1

Unfortunately, without knowing the original query, you can't know the underlying type. The type of the return value of an aggregate query is List<AggregateResult>. You will indeed need an additional parameter to supply this information.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.