Well, this is quite common requirement.
Lets assume a sample Rest Service.
@RestResource(urlMapping = '/submitcontact/*')
global class GenericContactCreator {
@HttpPost
global static void doPost(Contact con) { //Can be Sobject or some custom apex wrapper
//do something
}
}
If someone sends marformed JSON/XML the code wont even reach your apex class. The Java preporcessor will break it before hand. As code did not reach your apex code, you lost logging/debug logs
So what I do normally, is make rest method as parameterless, retrieve raw body from RestRequest
@RestResource(urlMapping = '/submitcontact/*')
global class GenericContactCreator {
@HttpPost
global static void doPost() {
String requestBOdy = RestContext.request.body.toString();
//The raw Request , LOG it, Parse it, your call. You have control to do it.
}
}
This gives you control to parse or log or do something about it. Also it removes the intimidating SF requirement of having outer layer of JSON /XML same as parameter name . In the above example con.
API Errors
in Salesforce and insert records to that object if any API calls fail. I'd also create a scheduled batch process that deletes these records after a certain period of time, otherwise your org is going to be filled with eventually-useless data. Then build a report off this object. – Drew Kennedy Aug 9 '19 at 16:37