You need to sign in to do that
Don't have an account?
Yogesh Biyani
queryCount fails with Use query() for non-count queries
I am using a dynamic query but it fails with Use query() for non-count queries . What am I missing?
for(Schema.ChildRelationship child : dsr.getChildRelationships()) { String query= 'select count(id) FROM CONTACT WHERE ID NOT IN (SELECT '+ child.getField()+' FROM '+child.getChildSObject()+ ')'; integer t=Database.countquery(query); system.debug(t); }
Will greatly appreciate if someone can help.
Thanks in advance.
Yogesh
To me it seems like you are trying to get the Count of the Contact but Id you matching with getField. I am kind of the lost of what exactly you wanted.
This is because return type of Database.countquery is Integer where as with COUNT(Id) return type is AggregateResult.
Below should work just fine:
for(Schema.ChildRelationship child : dsr.getChildRelationships()) {
String query= 'select count() FROM CONTACT WHERE ID NOT IN (SELECT '+ child.getField()+' FROM '+child.getChildSObject()+ ')';
integer t=Database.countquery(query);
system.debug(t);
}
Thanks