當用戶點擊case來更改caseOwner/user時,我必須將此用戶添加到所有關聯的案例(每個客戶)。我正在使用下面的代碼,但它只更新一個記錄/案例。我可以看到在調試日誌中,所有案例都用最新的所有者更新,但沒有真正更新/存儲在caseObject中。請幫助我。Apex觸發器 - 如何使用觸發器更新所有案例所有者?
trigger caseAssignment on Case (after insert, after update) {
set<id> ownerId = new Set<Id>();
set<id> customerId = new set<Id>();
for(Case caseobj : trigger.new){
ownerId.add(caseobj.OwnerId);
customerId.add(caseobj.AccountId);
}
for(User user:[Select id, FirstName, LastName from user where Id IN :ownerId]){
for(Case cas : [Select Id, OwnerId, First_Name__c, CaseNumber, AccountId From Case where AccountId IN: customerId]){
cas.OwnerId = user.Id;
}
}