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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


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
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.