Skip to main content
Jagriti Kukreti (RBC) が「#Apex」で質問
How to update an account field with value='abc' if any one of the corresponding opportunities have custom field test__c='xyz' via trigger?
1 件の回答
  1. 2019年10月27日 10:17
    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;
0/9000