function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MRITYUNJAY PATEL 3MRITYUNJAY PATEL 3 

i want to debug specific field of list.


Hi Everyone,
why showing variable not exist. give me solution

//This is my code

global class JsonParseringClass
{
    public static void getJSONData()
    {
        HTTP http = new HTTP();
        HTTPRequest request = new HTTPRequest();
        request.setEndpoint('https://jsonplaceholder.typicode.com/posts');
        request.setMethod('GET');
        HTTPResponse response = http.send(request);
        string res = response.getBody();
        system.debug(response.getStatus());
        List<BlogWrapper> blogObj = ( List<BlogWrapper>)JSON.deserialize(res,  List<BlogWrapper>.class);
       System.debug('Respone- ' + blogObj.id);
        System.debug('Respone- ' + blogObj.userId);
        System.debug('Respone- ' + blogObj.title);
        System.debug('Respone- ' + blogObj.body);
        //return blogObj;
      }
     
    global class BlogWrapper
    {
       public Integer userId { get; set; }
       public Integer id { get; set; }
       public string title { get; set; }
        public string body { get; set; }
    }
}

Thanks in advance
Best Answer chosen by MRITYUNJAY PATEL 3
SwethaSwetha (Salesforce Developers) 
HI Mrityunjay,
List<BlogWrapper> blogObj = ( List<BlogWrapper>)JSON.deserialize(res,  List<BlogWrapper>.class);
       System.debug('Response- ' + blogObj[0].id);
        System.debug('Response- ' + blogObj[0].userId);
        System.debug('Response- ' + blogObj[0].title);
        System.debug('Response- ' + blogObj[0].body);
        //return blogObj;
You need to use array of the blogObj to debug. I tried this in my org and it works.

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Mrityunjay,
List<BlogWrapper> blogObj = ( List<BlogWrapper>)JSON.deserialize(res,  List<BlogWrapper>.class);
       System.debug('Response- ' + blogObj[0].id);
        System.debug('Response- ' + blogObj[0].userId);
        System.debug('Response- ' + blogObj[0].title);
        System.debug('Response- ' + blogObj[0].body);
        //return blogObj;
You need to use array of the blogObj to debug. I tried this in my org and it works.

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
This was selected as the best answer
Suraj Tripathi 47Suraj Tripathi 47
Hi,
Please try the below code:-
List<BlogWrapper> blogObj = ( List<BlogWrapper>)JSON.deserialize(res,  List<BlogWrapper>.class);

for(BlogWrapper ins : blogObj  )
{       System.debug('Respone  id- ' +ins.id);
        System.debug('Respone   userId- ' + ins.userId);
        System.debug('Respone  title- ' + ins.title);
        System.debug('Respone  body- ' + ins.body);
    }

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi