function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jerry ClifftJerry Clifft 

For loop, not looping?

Ok, I find this weird, hoping for some help with the matter.  Here are the basics:

Trigger on account, when the Account field Flags__c does not contain "Delinquent", and the Case owner is 'xxx' (Delinquent) it should replace the owner with a new owner. It works fine, each time I save the account, 1 case record is being updated. What I need, is for all the cases with the owner of delinquent to be updated at the same time, I thought the for loop would do this, but it is not. Here is my trigger:



trigger AccountDelinquentHoldRelesed on Account (After Update) {

Account AC = Trigger.New[0];

    Set<Id> ACIds = new Set<Id>();
            ACIds.add(AC.Id);

       list<account> ACS = [select id, Flags__c from account where Id in :ACIds AND Flags__c EXCLUDES ('Delinquent') ];
       list<case> CAS = [select id, OwnerID from case where Case.AccountID in :ACS AND Case.OwnerID = '00G60000002Ia7P'];
   
       if(CAS.size() > 0 && ACS.size() > 0 ){
           for (Case CAS2: CAS) {  
               { CAS[0].OwnerID= '00G60000001Na1r';}
           }
       }
 }
Best Answer chosen by Jerry Clifft
Jerry ClifftJerry Clifft
I think I may have sold my own issue, seems I was missing the UPDATE(CAS); part.

trigger AccountDelinquentHoldRelesed on Account (After Update) {

Account AC = Trigger.New[0];

    Set<Id> ACIds = new Set<Id>();
            ACIds.add(AC.Id);

       list<account> ACS = [select id, Flags__c from account where Id in :ACIds AND Flags__c EXCLUDES ('Delinquent') ];
       list<case> CAS = [select id, OwnerID from case where Case.AccountID in :ACS AND Case.OwnerID = '00G60000002Ia7P'];
   
       if(CAS.size() > 0 && ACS.size() > 0 ){
           for (Case CAS2: CAS) {  
               { CAS2.OwnerID= '00G60000001Na1r';}
           }
           update(CAS);
        }
}