I'm working with some complicated queries, and I need to send over http, the sObject in turn, but I can't make queries with more than 1 level of depth in the SOQL, so I am working with separated queries, then composing the sObjects, (or at least that is what I try), so I can created a full json
for when I send the http request
, but It raises an exception
like this
System.SObjectException: Invalid field Object_A for Object_B
May be I'm doing it wrong, but I am trying to add the field as if it where a regular map or sobject
// meta is a metadata object with a fixed query string
// sidWhere is a string with the ID and the quotation marks just to append to the query
string soql_main = meta.SOQL_Fields__c + ' WHERE Id = ' + sidWhere;
sObject[] join1;
string soql_join_1 = meta.SOQL_Join_1__c + sidWhere;
string sObjTypeName1;
join_1 = database.query(soql_join_1);
sObjTypeName1 = join_1.getSObjectType().getDescribe().getName();
main.put(sObjTypeName1, join_1); // Here it throws the exception
So, what would be a better way to do this composition I say, It's just adding one field
to the main
sobject, that contains the list of sobjects from the query in soql_join_1
.
Any Ideas?
Edit
Let's say I have an ObjectB that It's related to ObjectA via a lookup, that means ObjectB has a field pointing to ObjectA. Now I want to get Object A and all the records that point to it of the ObjectB, but ObjectB also have records pointing to it of the type ObjectC, So I need to pull ObjectA with
id = sid
, and this will pull up all records ObjectB and does will pull their corresponding ObjectC'sThe problem is that, when I try to make a Double nested query from the ObjectA table, turns out to be unallowed, so I did a query to pull up, Exclusivly ObjectA fields, and another one different that gets a list of all the ObjectB objects, that relate to ObjectA, and their children. NOW I want to manipulate the sOjbectA so It contains the list of ObjectB's that came out from a different query. Because I need to send it outside as a Json.