You need to sign in to do that
Don't have an account?
sfdc learner 122
Simple Fix needed in Restapi testclass
Hi Team , i need help in fixing this test class
Wrapper Class:
public class AccountWrapper {
public List<accRecords> AccountList;
public class accRecords {
public String AccId;
public String NextVal;
}
public static AccountWrapper parse(String json){
return (AccountWrapper) System.JSON.deserialize(json, AccountWrapper.class);
}
}
My Apex Snippet:
Map<Id,String> accMap = new Map<Id,String>();
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String bodyJson = req.requestBody.toString();
AccountWrapper reqJSON = AccountWrapper.parse(bodyJSON);
for(AccountWrapper.accRecords acc : reqJSON.AccountList){
accMap.put(acc.AccId,acc.NextVal);
}
My test class is failing above highlighted line,i want to pass list of Account id in JsonBody
currently i am facing below error message
System.JSONException: Malformed JSON: Expected '{' at the beginning of object - i think this is i am passing single record
Wrapper Class:
public class AccountWrapper {
public List<accRecords> AccountList;
public class accRecords {
public String AccId;
public String NextVal;
}
public static AccountWrapper parse(String json){
return (AccountWrapper) System.JSON.deserialize(json, AccountWrapper.class);
}
}
My Apex Snippet:
Map<Id,String> accMap = new Map<Id,String>();
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String bodyJson = req.requestBody.toString();
AccountWrapper reqJSON = AccountWrapper.parse(bodyJSON);
for(AccountWrapper.accRecords acc : reqJSON.AccountList){
accMap.put(acc.AccId,acc.NextVal);
}
My test class is failing above highlighted line,i want to pass list of Account id in JsonBody
currently i am facing below error message
System.JSONException: Malformed JSON: Expected '{' at the beginning of object - i think this is i am passing single record
In your Apex snippet, you are expecting the JSON to contain an array of Account Records, but it seems you might be passing a single Account Record instead of an array. To fix this, you should ensure that your JSON input matches the expected format.
Each Account Record should be enclosed in curly braces {}.
Please mark this comment as best answer if it's help you.