2

My mock body looks like :

'{"totalSize": 1, "done":true,
"nextRecordsUrl":"WWW.testurl.com","records":[{"Name":"Fund1", "aduro__Date_of_Inception__c":"2011-10-09 00:00:00", "Accept_ACH_Payments__c":true,"ACH_Public_Key__c":"pk_sandbox_MTU4MmJhMDgtMTU4OC00YmVh","ACH_Secret_Key__c"
:"sk_sandbox_OTc0ZTVkMzQtYmM5Mi00MWU5"}]}'

And my wrapper looks like this:

public class QueryResponse {
        public Integer totalSize {get; set;}
        public Boolean done {get; set;}
        public String nextRecordsUrl { get; set; }
        public List<SObject> records {get; set;}
    }

The SObject in my case is fund__c. When i use i am getting the error as System.JSONException: Nested object for polymorphic foreign key must have an attributes field before any other fields.

1 Answer 1

5

The deserialization needs to know what concrete type to use and that is signalled by an attributes field:

"records":[{"attributes": {"type": "fund__c"}, "Name":"Fund1", ...

so if the system that generates the JSON can provide that, get it added.

Or if the records are always fund__c:

public List<fund__c> records {get; set;}

If the system that generates the JSON can't provide that, you will have to write more involved code that walks through the JSON and infers the type that you can then hard-code in the logic.

1
  • I wish the error response had a reference to this. I keep ending up on this post :) Nov 17, 2021 at 17:17

You must log in to answer this question.

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