• tim tito
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
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. 
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());
        }
        
    }
    
    
}
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. 
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());
        }
        
    }
    
    
}