You need to sign in to do that
Don't have an account?
degmo
Test coverage for a future method
Hello All,
I have an existing future method that does a callout to an external service. All it does is send data to an external service and if the response is not a 200, it just logs a message to the debug log. This method obviously doesn't return anything and it doesn't perform any action on the SF side that I can use to do my assertions.
I have created a mock class and used it to invoke this future method inside of Test.StartTest & Test.StopTest. I am getting 100% code coverage but I don't have any assertions. I am struggling with what to use for my assertions? Since the method doesn't return anything, I can't use the response from my mock class. Any thoughts? Here is a code snippet of the class
I have an existing future method that does a callout to an external service. All it does is send data to an external service and if the response is not a 200, it just logs a message to the debug log. This method obviously doesn't return anything and it doesn't perform any action on the SF side that I can use to do my assertions.
I have created a mock class and used it to invoke this future method inside of Test.StartTest & Test.StopTest. I am getting 100% code coverage but I don't have any assertions. I am struggling with what to use for my assertions? Since the method doesn't return anything, I can't use the response from my mock class. Any thoughts? Here is a code snippet of the class
@Future(Callout = true) public static void callExternalSystem(Id recordId) { String body = buildMessage(recordId); HttpRequest req = new HttpRequest(); req.setEndpoint('https://xyz.com/test'); req.setMethod('Post'); req.setHeader(''); req.setBody(body); Http http = new Http(); HttpResponse response = http.send(req); if(response.getStatusCode() != 200) { system.debug('Status is: ' + response.getStatus + ' ' + response.getBody()); } } public static string buildMessage(Id recordId) { // logic to build the request body }
For code snippet, you can go through the below developer discussion,
https://salesforce.stackexchange.com/questions/65653/how-to-test-a-future-method-which-makes-callouts
https://developer.salesforce.com/forums/?id=906F000000094QOIAY
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.