我的批处理作业类如下:
global class GroupMemberSearch implements Database.Batchable<SObject>{
global String groupQuery;
global final Map<Id, Group> groupIdMap;
global GroupMemberSearch(String groupQuery){
system.debug(groupQuery);
this.groupQuery = groupQuery;
}
global Database.QueryLocator start(Database.BatchableContext BC){
system.debug('In batch start');
return Database.getQueryLocator(groupQuery);
}
global void execute(Database.BatchableContext BC, List<SObject> scope){
system.debug(scope);
List<groupInfo> grpMemberList = new List<groupInfo>();
for(Group s : (List<Group>)scope){
system.debug(s);
groupInfo newGroup = new groupInfo();
if(s.Name != null){
set<Id> memberIdSet = getGroupMembers(new set<Id>{s.Id}, 0);
if(memberIdSet.size() != 0){
newGroup.groupId = s.Id;
newGroup.groupName = s.Name;
newGroup.groupMemberIds = memberIdSet;
grpMemberList.add(newGroup);
}
}
}
system.debug(grpMemberList);
}
global void finish(Database.BatchableContext BC){}
private set<Id> getGroupMembers(set<Id> groupIds, Integer queryLimit){
set<Id> nestedIds = new set<Id>();
set<Id> returnIds = new set<Id>();
if(queryLimit < 5){
List<GroupMember> members = [SELECT Id, GroupId, UserOrGroupId FROM GroupMember WHERE GroupId IN :groupIds];
for(GroupMember member : members){
if(Schema.Group.SObjectType == member.UserOrGroupId.getSObjectType()){
nestedIds.add(member.UserOrGroupId);
} else{
returnIds.add(member.UserOrGroupId);
}
}
}
queryLimit++;
if(nestedIds.size() > 0){
returnIds.addAll(getGroupMembers(nestedIds, queryLimit));
}
return returnIds;
}
public class groupInfo{
public String groupId;
public String groupName;
public set<Id> groupMemberIds;
}
}
在我的顶点控制器中,我打电话给
Id batchProcessId = Database.executeBatch(new GroupMemberSearch('SELECT Id, OwnerId, Name, Email FROM Group WHERE Name != null'), 20);
返回批处理ID,我从apex批处理作业构造函数中看到system.debug ...但是,我没有看到任何来自start和execute方法的system.debugs ...我将我的日志限制为只显示调试语句,它们不在任何地方。我知道我的查询返回一个组列表,即使它没有,我仍然应该在返回之前从start方法看到system.debug ...
我希望在加载页面时运行此批处理作业,因此它位于apex控制器的构造函数中。
知道为什么启动和执行方法没有被运行?
感谢您的帮助!