You need to sign in to do that
Don't have an account?
tim tito
How to create test class to improve code coverage.
Hi All,
I have developed a trigger for contact on update. as soon as contact update am calling below class from tigger and passing contact id. I am new to write test class for call outs. Can someone help to create test class for below method.
Thanks in adcance.
I have developed a trigger for contact on update. as soon as contact update am calling below class from tigger and passing contact id. I am new to write test class for call outs. Can someone help to create test class for below method.
Thanks in adcance.
public class Helper { public static String api_end_point = 'URL'; @future (callout=true) public static void afterUpdateContact(String contact_id){ String post_body = '{"data": {"contactId":"' + contact_id + '"}}'; Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(api_end_point); request.setMethod('POST'); request.setHeader('Content-Type', 'application/json;charset=UTF-8'); request.setBody(post_body); HttpResponse response = http.send(request); if (response.getStatusCode() != 201) { System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus()); } else { System.debug(response.getBody()); } } }
To create the Test class for an Apex class that performs callout you have to create a Mock class which the sample response that you may receive when the actual callout happens.
Create the following test class.
And the following class is the mock class for the test class created above. You can change the Header and Response values accordingly.
Let me know if any problem occurs.
Thanks, Ayush Sharma
Created as per instructions and still code coverage shwoing 0.
Any other inputs?
Thank you
Can you show me the code from where you are calling this future method?