Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm trying to test a class I'm using with a Trigger. The Trigger fires when events and tasks are created/modified/deleted.

I'm able to test the task creation just fine, but when I try to test the event creation with the code below I'm greeted with a 'Methods defined as TestMethod do not support Web service callouts, test skipped' message on the line where I'm creating the event.

Event e = new Event(subject='Test Event', whatId = account.id, 
          startDateTime = DateTime.valueOf('2014-04-26 14:45:05'), 
          endDateTime = DateTime.valueOf('2014-04-26 14:45:05'));
insert e;

//Verify count = 1
account = [SELECT ID, activity_count__c FROM Account WHERE ID = :account.id];
System.assertEquals(1, account.activity_count__c);

I've tried using System.now() to set my dates as well as what you see above. Both provide me with the same results. Any ideas of what I'm missing?

share|improve this question

1 Answer 1

When you get that message, no line number is reported so the problem is probably occuring on insert e.

This contrived code will produce that error:

@isTest
public class MyTest {

    @isTest
    static void test() {
        Account a = new Account(Name = ' Acme');
        insert a;
        Event e = new Event(
                Subject = 'Test Event',
                WhatId = a.id, 
                StartDateTime = DateTime.valueOf('2014-04-26 14:45:05'), 
                EndDateTime = DateTime.valueOf('2014-04-26 14:45:05')
                );
        insert e;
    }

    @future(callout=true)
    public static void callout() {
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://google.com');
        req.setMethod('GET');
        HttpResponse res = new Http().send(req);
    }
}

where the insert causes some other code (trigger or workflow rule) to make a callout:

trigger MyTrigger on Event (before insert) {
    MyTest.callout();
}

Assuming you find there is a callout, you can mock it in your test to allow your test to run. (If you are not sure where it is, turn on the debug logging and run the test again and check the log.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.