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
ForceRookieForceRookie 

Body is null and how to solve this error: System.JSONException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

Please help me. What's wrong with my Queueable Class?

public class FolderDisplayInfo implements Queueable, Database.AllowsCallouts {
    public List<Folder__c> fld; 
        public FolderDisplayInfo(List<Folder__c> folderList) {
                fld = folderList;
        }

        public void execute(QueueableContext context) {
            System.debug('Folders: ' + fld);
            Http http = new Http();
            HttpRequest httpReq = new HttpRequest();
            httpReq.setMethod('GET');
            httpReq.setHeader('Content-Type','application/json');
            httpReq.setEndpoint('<my endpoint>');
            HttpResponse res = http.send(httpReq);
            System.debug('Response: ' + res);
            if(res.getstatusCode() == 200 && res.getbody() != null){
                response = (List<cls_Response>)JSON.deserialize(res.getBody(), List<cls_Response>.class);
                System.debug('Body: ' + res.getBody());
            }
            //update folders here...

    }

    public class cls_Response {
        public String folderName {get;set;}
        public String recordID{get;set;}
        public String parentFolder{get;set;}
        public String bucketID{get;set;}
    }
    public List<cls_Response> response {get;set;}
}


Help me to get this response:

"00BO00000ABCD60EFG" : { //Record Id
	   "folders" : [ //Object
		   {
			"name" : "foldertest",
			"sfid" :  "00B0000ABC3ab",
			"parent" : "<FOLDER LOOKUP field>",
			"folderID" : "<BUCKET ID>",
			"RecordID" : "<Record ID>"
				
		   }	
		],
}
RajeshPunjabiRajeshPunjabi
Hi Force,

Can you please share RAW response before deserialising?

Thanks.
 
ForceRookieForceRookie
DEBUG|Folders: (Folder__c:{Id=00BN000000LRgD3IAL, Name=Sample}, Folder__c:{Id=00BN000000LRgD8IAL, Name=FolderTest})

DEBUG|Response: System.HttpResponse[Status=OK, StatusCode=200]

You mean that?

Thanks for replying, Rajesh!

ForceRookieForceRookie
This is the error:
System.JSONException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [3,2]

Class.System.JSON.deserialize: line 14, column 1

Class.FolderDisplayInfo.execute: line 17, column 1

 
RajeshPunjabiRajeshPunjabi
Yes, so you response is good.

look like (not 100% sure though) special characters in json may be causing this issue. have you validated your json?

Try this https://www.freeformatter.com/json-escape.html or jsonlidator

 
ForceRookieForceRookie
I honestly don't know what to do, can you help me with my code to get the JSON response above? -,-
RajeshPunjabiRajeshPunjabi
Sure, do you have sample json file you are execting?

Thanks.
ForceRookieForceRookie

Here is the JSON I should get:

"00BO00000ABCD60EFG" : { //Record Id
	   "folders" : [ //Object
		   {
			"name" : "foldertest",
			"salesforceID" :  "00B0000ABC3ab",
			"parent" : "<FOLDER LOOKUP field>",
			"folderID" : "<BUCKET ID>", //Key
			"RecordID" : "<Record ID>"
		        "CreatedDate" : "<Date>"
		   }	
		],
}
ForceRookieForceRookie
Thanks Rejesh, I hope you can help me. It's my problem for 5days now.
RajeshPunjabiRajeshPunjabi
Hi,

Here is your correct json:
{"RecordId" : { 
	   "folders" : [ 
		   {
			"name" : "foldertest",
			"salesforceID" :  "00B0000ABC3ab",
			"parent" : "<FOLDER LOOKUP field>",
			"folderID" : "<BUCKET ID>",
			"RecordID" : "<Record ID>",
		        "CreatedDate" : "<Date>"
		   }	
		]
}
}

and apex:
 
//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

public class JSON2Apex {

	public RecordId RecordId;

	public class Folders {
		public String name;
		public String salesforceID;
		public String parent;
		public String folderID;
		public String RecordID;
		public String CreatedDate;
	}

	public class RecordId {
		public List<Folders> folders;
	}

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

Let me know if still an issue.

URL: https://json2apex.herokuapp.com/

Thanks
ForceRookieForceRookie
Thanks, Rajesh. But I think this code format will not work for mine, I have to callout to AWS using Queueable Class. Like what I did above.
RajeshPunjabiRajeshPunjabi
Hi,

Still OK, what I have shared is base code. I am sure it will work.

Regards,
Raj