ServiceNowBatch
//Authentication + request done (req and res)
// (...)
List<Case> casesToUpdate = new List<Case>;
String response = res.getBody();
//Having problems here
CaseWrapper caseWrapperDes = (CaseWrapper)JSON.deserialize(response, CaseWrapper.class);
System.debug('caseWrapper content: '+caseWrapperDes);
// (...)
for (CaseWrapper SNcase : caseWrapperDes) {
if (response.length() > 0 && response.substring(0, 5) != 'Error') {
Case c = new Case();
c.description = SNcase.description;
c.origin = SNcase.contact_type;
casesToUpdate.add(c);
}
}
return casesToUpdate;
(...)
CaseWrapper
CaseWrapper
public class CaseWrapper {
public List<resultSN> results {get; set;}
public class resultSN {
public String short_description {get; set;}
public String sys_id {get; set;}
public String contact_type {get; set;}
public String incident_state {get; set;}
public String impact {get; set;}
public String description {get; set;}
}
}
CaseWrapperList
I don't know what I'm missing.CaseWrapperList
public class CaseWrapperList {
public List<CaseWrapper> results;
}
For starters, your JSON says the field name is "result" but in your CaseWrapper class it's called "results".
Also, line 11
for (CaseWrapper SNcase : caseWrapperDes) {
should probably be
for (CaseWrapper.resultSN SNcase : caseWrapperDes.results) {
It's also against convention to start class names like "resultSN" with a lowercase letter, although it will still run just fine.
Lastly, I would move the if statement out of the loop. The condition does not depend on your loop variable SNcase, it will be either true for all of them or false for all of them. This just wastes CPU cycles. You should do the check once, and if it's true then enter your code block
if (response.length() > 0 && response.substring(0, 5) != 'Error') {
CaseWrapper caseWrapperDes = (CaseWrapper)JSON.deserialize(response, CaseWrapper.class);
System.debug('caseWrapper content: '+caseWrapperDes);
for (...) {
//do stuff
}
}