-1

My question is similar to this. I'm trying to create a Case and process few child task records from a REST API Call.

REST API Endpoint POC:

enter image description here

But when I executed this as below, I get error System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop\n\nExternal entry point in above highlighted line which is a System.debug(). If I remove the debug line no errors.

enter image description here

Also note it doesn't go inside the for loop. Any ideas how to deserialize this and create the SObject with it's related records? Is it not possible to follow this approach to receive related records?

Any thoughts/suggestions are much appreciated. Thanks!

1 Answer 1

1

This error occurs because the JSON doesn't include the done property, or it is set to false.

//Note "done": false
String s = '{"attributes":{"type":"Case"},"Subject":"Demo","Tasks":{"size":"1","done":false,"records":[{"attributes":{"type":"Task"},"Subject":"Demo"}]}}';
Case c = (Case)JSON.deserialize(s, Case.class);
System.debug(c);
// Exception thrown here
System.debug(''+c.Tasks);

// Runs to completion
//Note "done": true
String s = '{"attributes":{"type":"Case"},"Subject":"Demo","Tasks":{"size":"1","done":true,"records":[{"attributes":{"type":"Task"},"Subject":"Demo"}]}}';
Case c = (Case)JSON.deserialize(s, Case.class);
System.debug(c);
System.debug(''+c.Tasks);

Make sure that the size and done properties are set correctly, or you can expect this type of exception if you do certain things, such as trying to toString or assigning the property to a List<Task>.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .