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.


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;

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.