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
Gavin JolleyGavin Jolley 

Error When deploying to production - TestMethod do not support Web service callouts

Hi Team,
I have inherited an org that has a good amount of custom delelopment done by a previous full time developer.

I would like to deploy a slight update to a trigger but when I deploy I get the error - TestMethod do not support Web service callouts when running the apex tests.

The test that fails is this one...

@isTest(seealldata=true) 
public class MilestoneUtilsTest
 {
     static testmethod void testMethod2(){
         Account acc1 = new Account();
            acc1.name = 'Test Account';
            insert acc1;
String milestoneName='Test';
DateTime complDate = DateTime.newInstance(2012, 7, 09, 3, 3, 3);
Case cs1 = new case();
          
            
           cs1.AccountId=acc1.id;
         cs1.Priority='High';
         cs1.Subject='Test';
            insert cs1;
            
            List<id> caseids=new List<id>();
        caseids.add(cs1.id);

    MilestoneUtils.completeMilestone(caseIds, milestoneName, complDate);
    
 List<CaseMilestone> caseMilestones = [select Id, completionDate from CaseMilestone cm where caseId in :caseIds];
    system.debug('**1**' + caseMilestones.size());
    for (CaseMileStone cm : caseMilestones) {
        cm.CompletionDate = System.today();
    }

    update caseMilestones;
         
         
     }
   
static testMethod void CloseCaseTest() {
// TO DO: implement unit test

Account acc = new account(name = 'TestCoverage');
insert acc;
Contact con = new contact(accountId = acc.id, lastname='Coverage', firstname='Test');
insert con;
Asset ass = new asset(name = 'TestAsset', accountId = acc.id);
insert ass;
Entitlement ent = new entitlement(name = 'TestEnt', accountId = acc.id);
insert ent;


Case cseA = new case(accountId = acc.id, contactId = con.id, subject = 'TestCoverage1', EntitlementId = ent.Id, Reason = 'Software Query', Type= 'Help Request', Description = 'Test Coverage'); 
insert cseA; 

List<CaseMilestone> CaseMls = [select Id, completionDate from CaseMilestone
where caseId = :cseA.Id ];

cseA.status = 'Closed';
try{
update cseA; 
}catch(Exception e){
if(CaseMls.isEmpty() == false){ 
for (CaseMilestone cm : CaseMls){
if(cm.completionDate == null)
{
// system.assertEquals(e.getMessage(), 'The completion Date of Case Milestone(s) must be filled to close the case');
}
}
}
}
}
}
 

Is anyone able to help me identify where the web call out is happening... (sorry I'm not a developer)

Thanks
Gavin

Ramesh DRamesh D
@Gavin
It must be in this method
MilestoneUtils.completeMilestone(caseIds, milestoneName, complDate);
try adding mock class to the testmethod must solve your problem 
Test.setMock(HttpCalloutMock.class, new YourHttpCalloutMockImpl());

Thanks
Ramesh
Gavin JolleyGavin Jolley
Hi,
Here the MilestoneUtils.completeMilestone class.

Where would I put your code suggestion? 
 
public class MilestoneUtils {
    public static void completeMilestone(List<Id> caseIds, 
            String milestoneName, DateTime complDate) {  
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
            from CaseMilestone cm
            where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName 
            and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
        for (CaseMilestone cm : cmsToUpdate){
            cm.completionDate = complDate;
            }
        update cmsToUpdate;
        }
    }
}

 
Ramesh DRamesh D
Looks like not he above method as well, your trigger must be firing multiple calls. Find out all the calls fired when CaseMilestone is updated/instered, there must be some https calls firing.