Sign up ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.


What is the most efficient way to transform aggregate results to string object maps?


The keys of the aggregated results are unknown. The transformation has to be performed as efficient as possible.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Suggested solution:

Convert a list of aggregate results to a Json string and deserialize the string as an object.

    List<Map<String, Object>> getAggregateResultAsMap(List<AggregateResult> aggrs)
        String js = Json.serialize(aggrs); // AggregateResult as Map
        List<Map<String, Object>> result = new List<Map<String, Object>>(); // result Object
        Object resultObject = Json.deserializeUntyped(js); // deserialized without type
        for (Object o : (List<Object>) resultObject)
            result.add((Map<String, Object>) o);
        return result;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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