I tried to answer it below.
The program is as follows.
** BatchUpdateUser **
global without sharing class BatchUpdateUser implements Database.Batchable , Database.Stateful {
global String NAME = 'User';
global BatchUpdateUser() {
}
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator([
SELECT
Id
, UserId__c
, UserRoleId__c
, ProfileId__c
, Group__c
, IsActive__c
FROM Work__c
WHERE
Name = :NAME
]);
}
global void execute(Database.BatchableContext BC, List<sObject> scope) {
List<Work__c> works = (List<Work__c>) scope;
List<String> userIds = new List<String>();
for (Work__c w : works) {
userIds.add(w.UserId__c);
}
List<User> users = [
SELECT
Id
, UserRoleId
, ProfileId
, Group__c
, IsActive
FROM User
WHERE
Id = :userIds
];
Map<Id, User> userMap = new Map<Id, User>(users);
for (Work__c w : works) {
userMap.get(w.UserId__c).UserRoleId = w.UserRoleId__c;
userMap.get(w.UserId__c).ProfileId = w.ProfileId__c;
userMap.get(w.UserId__c).Group__c = w.Group__c;
userMap.get(w.UserId__c).IsActive = w.IsActive__c;
}
update userMap.values();
}
global void finish(Database.BatchableContext BC) {
}
}
** UserTrigger **
trigger UserTrigger on User (after insert, after update) {
Set<ID> trueIds = new SET<ID>();
for(User u : Trigger.new) {
if(u.LandingGoalFlg__c == true) {
trueIds.add(u.Id);
}
}
if(Trigger.isInsert && Trigger.isAfter){
if(trueIds.size() != 0) {
LandingBusinessConditionHandler.OnAfterUpsertAsync(trueIds);
}
} else if(Trigger.isUpdate && Trigger.isAfter){
if(trueIds.size() != 0) {
LandingBusinessConditionHandler.OnAfterUpsertAsync(trueIds);
}
}
}
** LandingBusinessConditionHandler **
Public class LandingBusinessConditionHandler {
@future
Public static void OnAfterUpsertAsync (Set <Id> newUserIds) {
OnAfterUpsertAsync(newUserIds);
}
Public static void OnAfterUpsertSync(Set <ID> newUserIDs) {
// do something
}
}
However, I got an simller error
I would be pleased if you could point out the wrong part.
BatchUpdateUser bc = new BatchUpdateUser(); Database.executeBatch(bc);