I am getting the following JSON from api and trying to add some of the variables in the list of "filings" to a custom object.

  "status": 0,
  "success": true,
  "message": "string",
  "errors": [
      "subCode": "string",
      "message": "string"
  "data": {
    "configuredWorkflow": [
        "name": "string",
        "requiresCommentToTransition": true,
        "rank": 0
    "filings": [
        "referenceId": "string",
        "title": "string",
        "reportId": "string",
        "workflowStep": "string",
        "comments": "string",
        "accountId": "00000000-0000-0000-0000-000000000000",
        "accountName": "string",
        "companyId": "00000000-0000-0000-0000-000000000000",
        "companyName": "string",
        "countryCode": "string",
        "dueDate": "2020-05-28T08:00:38Z",
        "filingArtifact": "string",
        "filingArtifactName": "string"
    "count": 0

I have used http://json2apex.herokuapp.com/ to create following class:

public class JSON2Apex {

    public class Errors {
        public String subCode;
        public String message;

    public Integer status;
    public Boolean success;
    public String message;
    public List<Errors> errors;
    public Data data;

    public class Data {
        public List<ConfiguredWorkflow> configuredWorkflow;
        public List<Filings> filings;
        public Integer count;

    public class ConfiguredWorkflow {
        public String name;
        public Boolean requiresCommentToTransition;
        public Integer rank;

    public class Filings {
        public String referenceId;
        public String title;
        public String reportId;
        public String workflowStep;
        public String comments;
        public String accountId;
        public String accountName;
        public String companyId;
        public String companyName;
        public String countryCode;
        public String dueDate;
        public String filingArtifact;
        public String filingArtifactName;

    public static JSON2Apex parse(String json) {
        return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);

I then pass json to the class and get the list of filings. I want to to loop through and then refer to variables from the Fileing class but cant.

   JSON2Apex class1 = JSON2Apex.parse(workflowResponse);
       list<object> filingslist  = class1.data.filings;
       for(Object eachfiling : filingslist){               


How do I get at the different variables in "eachfiling" . what else do I need to do to ?

  • 2
    Why are you typing filingsList as a List<Object>? I'd imagine that your problems will disappear if you used the appropriate type (List<JSON2Apex.Filings>). As usual, if you're getting an error, you should include the full text of the error, verbatim. You should also use the appropriate type for your loop variable. – Derek F May 28 at 14:11
  • why not use Json.deserialize instead of JSON2Apex.parse? – cropredy May 28 at 19:34

This solves your problem:

JSON2Apex class1 = JSON2Apex.parse(wf);
list<JSON2Apex.Filings> filingslist  = class1.data.filings;

 for(JSON2Apex.Filings m : filingslist){    
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.