1 件の回答
Set<Id> setAccIds= new Set<Id>();List<Account> accountsToUpdate = new List<Account>();for(Opportunity opty : [SELECT Id, AccountId FROM Opportunity WHERE Id IN :trigger.new]){if(opty.test__c == 'xyz'){setAccIds.add(opty.AccountId);}}if(setAccIds != null && setAccIds.size() > 0){for(Account account : [SELECT Id, accField__c FROM Account WHERE Id IN :setAccIds ]){account.accField__c = 'abc';accountsToUpdate.add(account);}}if(!accountsToUpdate.isEmpty()) update accountsToUpdate;