I am performing a dynamic query on case feed and fetching few fields including CaseNumber
. queryResult
is storing the results but it does not contain casenumber
. I am able to retrieve caseNumber
with system.debug(abc.getSObject('parent').get('casenumber')
, but I need to store it in the queryResult
.
I have tried this but it gives error System.SObjectException: Invalid relationship Parent.casenumber for CaseFeed
.
Is there any workaround to store casenumber
value in the same queryResult
.
String queryString = 'select id,type,parentid,parent.casenumber,createddate from casefeed where type = \'textpost\'';
List<SObject> queryResult = Database.query(queryString);
for(sobject abc : queryResult){
system.debug(abc.getSObject('parent').get('casenumber'));
abc.putSobject('Parent.casenumber',abc.getSObject('parent').get('casenumber'));
}
queryResult
and that is how you are fetching it. is there something I am missing? – manjit5190 Jul 31 '20 at 9:28Database.query
does not fetch parent object field values. So,queryResult
will only haveparentid
but it cannot fetch any other parent field includingcasenumber
. I can fetch it usingabc.getSObject('parent').get('casenumber')
, but I would want to add it inList<SObject> queryResult
– devforce Jul 31 '20 at 9:31String queryString = 'select id,type,parentid,parent.status,createddate from casefeed'; List<SObject> queryResult = Database.query(queryString); System.debug(JSON.serializePretty(queryResult));
OR simple by debuggingSystem.debug(((CaseFeed) abc).Parent.Status')
inside the loop. – manjit5190 Jul 31 '20 at 9:33casenumber
with various different ways, I can use the option that you have mentioned or the option I had added in question but I would need this inList<SObject> queryResult
, that's where I am facing issue. If I convertJSON.serializePretty(queryResult)
tolist<sobject>
using(List<SObject>) JSON.deserialize(serialized, List<SObject>.class);
, it will not show any parent object field value apart fromID
field. – devforce Jul 31 '20 at 10:11List<Sobject>
, why would need to deserialize it. I just addedJSON.serializePretty
to show the result as when you debug it directly it does not show parent fields in the console but parent fields are actually there. It is not actually required. Also, to simplify things you can move away from dynamic query and just use a simple SOQL, if that is an option. – manjit5190 Jul 31 '20 at 10:15