function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John McAfeeJohn McAfee 

testclass fails at incert Case with TestMethod do not support Web service callouts

Test class below that was working perfectly is now failing with "Methods defined as TestMethod do not support Web service callouts" I have narrowed it down to the case insert line insert c; .  Is this a permissions issue on the case object ? all the other inserts work .

@isTest

public class DefaultEntitlementTest {
     static testmethod void ValidateDefaultEntitlementAction() {
        Account[] acc = new Account[] {
            new Account(Name='Test Account 1'),
            new Account(Name='Test Account 2')
        };
        insert acc;
       
        Contact[] contacts = new Contact[] {
            new Contact(FirstName='Test 1', LastName='McTesty', AccountId = acc[0].id),
            new Contact(FirstName='Test 2', LastName='McTesty', AccountId = acc[0].id)
        };
        insert contacts;
       
        Id entitlementProcessId = [SELECT Id FROM SlaProcess WHERE SObjectType = 'Case' LIMIT 1].Id;
       
        Entitlement[] ent = new Entitlement[] {
            new Entitlement (AccountId=acc[0].Id, SLAProcessId = entitlementProcessId, Name = 'Test Entitlement Account',
                                           StartDate = system.today(), EndDate = system.today()),
            new Entitlement (AccountId=acc[1].id, SLAProcessId = entitlementProcessId, Name = 'Test Entitlement Contact',
                                           StartDate = system.today().addDays(-1), EndDate = system.today().addDays(5))
        };
        insert ent;
       
        EntitlementContact ec = new EntitlementContact(ContactId = contacts[0].id, EntitlementId = ent[1].id);
        insert ec;
       
        Case c = new Case(AccountId = acc[0].id, ContactId = contacts[0].id, Subject='Test');
        insert c;
        
        List<Case> caseList = new List<Case>{c};
       
        DefaultEntitlementAction.updateDefaultEntitlements(caseList);
    }
}
 
Best Answer chosen by John McAfee
Abdul KhatriAbdul Khatri
Hi John,

Do you have a new code that is making http callout? That is impacting your existing test class, you need to update the Test class to make it work.

Here is the link for you reference

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm

All Answers

Abdul KhatriAbdul Khatri
Hi John,

Do you have a new code that is making http callout? That is impacting your existing test class, you need to update the Test class to make it work.

Here is the link for you reference

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
This was selected as the best answer
John McAfeeJohn McAfee
Thanks found that I had another class added recently that used a call out. I added the following to get past it. 

Test.setMock(HttpCalloutMock.class, new TestMockService());


    //Mockup service
    private class TestMockService implements HttpCalloutMock {

        public HTTPResponse respond(HTTPRequest req) {
              String response;
              HTTPResponse res = new HTTPResponse();
              res.setStatusCode(200);
              return res;

        }
    }
 
Abdul KhatriAbdul Khatri
Hi John,

So was my response helpful. Please mark it best if it was?
Abdul KhatriAbdul Khatri
Hi John,

Just following up to see if I was being helpful on this.