Я следующие услуги:Как проверить методы @future
public with sharing class LibraryService {
public static void remove(String jsonString) {
Library__c library = [ SELECT Id, ilms__Library_Name__c FROM ilms__Library__c WHERE Id = libraryId ] ;
AccessService.deleteReviewerGroup(library);
delete library;
}
}
класс AccessService
public with sharing class AccessService {
public static void deleteLibraryReviewerGroup(Library__c library) {
List<Library__Share> reviewersGroups = [ SELECT UserOrGroupId FROM ilms__Library__Share WHERE AccessLevel = 'Read' AND ParentId = :library.Id ];
System.debug('reviewersGroups: ' + reviewersGroups);
if(reviewersGroups.size() == 1) {
String reviewersGroupId = reviewersGroups[0].UserOrGroupId;
delete reviewersGroups;
AccessService.deleteReviewerGroup(reviewersGroupId);
}
return;
}
@future
public static void deleteReviewerGroup(String groupId) {
List<Group> reviewerGroup = [ SELECT Id FROM Group WHERE Id = :groupId ];
delete reviewerGroup;
}
}
Теперь, когда я пытаюсь протестировать LibraryService удалить метод, я продолжаю получать ошибку ниже :
first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa).
@isTest(SeeAllData=true)
private class TestLibrary {
static testMethod void testRemoveLibrary() {
Library__c library = new Library__c(...);
Boolean isRemoved = LibraryService.remove(TestUtilsClass.idJson(library.Id));
System.assertEquals(isRemoved, true);
}
}
Я попытался добавить Test.startTest() и Test.stopTest() для метода testRemoveLibrary, но я все равно получаю ту же ошибку. Я делаю что-то неправильно? Как это исправить?
Какая строка в вышеуказанном коде бросает ошибку? –