I have an apex trigger f_contactPushNotificationTrigger that should fire when a new contact is created. This trigger call f_PushNotification class used to Post data.

I used @future to make this task asynchronous Since the trigger makes HTTP callouts. Correct no?

The problem I am facing is creating a testing unit for the trigger and f_PushNotification class so I can deploy my code.

I have tried the Mock generation response (but the problem I am facing is that @future does not make it possible to return the response) and Test.StartTest() but both not working.

Below the error I got:

f_contactTriggerTest test Methods defined as TestMethod do not support Web service callouts Stack Trace: null

f_GetRelatedContactsId test Methods defined as TestMethod do not support Web service callouts Stack Trace: null

So it seems a conflict is happening with another trigger: f_GetRelatedContactsId that runs after insert on contact but does not have any HTTP callout.

So should I also stop this trigger for testing?

Could you please help me!


trigger f_contactPushNotificationTrigger on Contact (after insert) 
      for(contact con:trigger.new)


public class f_PushNotification {

@future (callout=true)
public static void sendNotification(String text) {

    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setHeader('Content-Type', 'multipart/form-data;charset=UTF-8');
    // Set the body as a JSON object
    HttpResponse response = http.send(request);
    // Parse the JSON response
    if (response.getStatusCode() != 201) 
            System.debug('The status code returned was not expected: ' +
                        response.getStatusCode() + ' ' + response.getStatus());



public class f_contactPushNotificationTest
    @isTest static void testCallout() 
        Contact con = new Contact (FirstName = 'FnamePushNotification');
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        insert con;

Testing documentation I followed:


Mock Generation:

global class MockHttpResponseGenerator implements HttpCalloutMock {
    // Implement this interface method
    global HTTPResponse respond(HTTPRequest req) {
        // Optionally, only send a mock response for a specific endpoint
        // and method.
        System.assertEquals('https://forestsal.xyz/sendNotification.php', req.getEndpoint());

  System.assertEquals('Post', req.getMethod());
    // Create a fake response
    HttpResponse res = new HttpResponse();
    res.setHeader('Content-Type', 'application/json');
    return res;
  • 1) You have to have testmethods on triggers to deploy; 2) the second error looks related to a different testmethod. Solve one problem at a time; 3) use edit to show your mock HTTP class; 4) are there multiple triggers on Contact or just the one (again, use edit)?. Avoid answering in comments
    – cropredy
    Commented Feb 6, 2020 at 19:18
  • @cropredy Thank you for your comment. I have updated my question. Could you please help
    – MRDRAG
    Commented Feb 7, 2020 at 12:07
  • It seems to me that you have multiple triggers firing on Contact insert. Best practice is to have a single trigger per SObject and dispatching to trigger handler class(es)
    – cropredy
    Commented Feb 7, 2020 at 14:16

1 Answer 1


The problem was the importance of applying the System.assertEquals() method which ensured the code coverage.

Thank you for your support.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .