0

I am trying to create a wrapper class to hold the JSON response in my apex class. But I am getting the error ' Inner types are not allowed to have inner types '. Below is my wrapper class.

public class GetTheDetails {

// Wrapper class

public class fromJSON{
    public String SId;  
    public List<valueRanges> valueRanges ;
    public class valueRanges {
        public String range;    
        public String majorDimension;   
        public List<values> values;
    }
    public class values {
        public String Id;           //Id
        public String AccountID;    //AccountId
        public String CreatedById;  //CreatedById
        public String Name;         //Name
        public String StageName;    //StageName
        public String CloseDate;    //CloseDate
    }
    public fromJSON parse(String json){
        return (fromJSON) System.JSON.deserialize(json, fromJSON.class);
    }
    
} }

Can anybody help me in identifying the error ? I am not able to find any syntax error in defining wrapper class here.

1 Answer 1

4

You need to move the definition of ValueRanges outside of the fromJSON class (same as you have for values).

So your code should be something like:

public class GetTheDetails {

  // Wrapper class
  public class fromJSON {
    public String SId;  
    public List<valueRanges> valueRanges ;
  }

  public class values {
    public String Id;           //Id
    public String AccountID;    //AccountId
    public String CreatedById;  //CreatedById
    public String Name;         //Name
    public String StageName;    //StageName
    public String CloseDate;    //CloseDate
  }

  public class valueRanges {
    public String range;    
    public String majorDimension;   
    public List<values> values;
  }
    
   public fromJSON parse(String json) {
     return (fromJSON) System.JSON.deserialize(json, fromJSON.class);
   }
    
}
1
  • Thanks user1067017 ! It worked. Dec 24, 2020 at 10:11

You must log in to answer this question.

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