SOQL Query – How to Replace a SOQL Query with a String

querysoqlstring

Any idea how to convert a query into a string?

Best Answer

Instead of for (List<AggregateResult> agg: query) you should have for (List<AggregateResult> agg: Database.query(query)).

You can find additional detail regarding Dynamic SOQL here.

Best regards!