I've got a tricky question, my code doesn't work - suprise. I would like to return only a list of 'filtred' data but my code never leav a if condition. So when if condition return true and my script go inside if body, it never go outside. I can not use a break.

for(ccrz.cc_bean_EffectiveAccount eff :effectiveAccount ){
        System.debug('nonetraid ' + noneTradingAccountIds);
        System.debug('eff.sfid ' + eff.sfid);
                System.debug('nonetraid w if' + noneTradingAccountIds);
                Integer indexOf = effectiveAccount.indexOf(eff);
                System.debug('indexof' + indexOf);
                effectiveAccount2 = effectiveAccount;
                System.debug('effacc loop' + effectiveAccount);
  //                    break;

Any idea ?

  • Do you mean that your code stuck in infinite loop by "it never go outside"? Ideas is that collection, iterated in loop should never be changed inside a loop to avoid such kind of things – kurunve Mar 25 '20 at 22:02
  • I believe it is because you are iterating and modifying the same list at the same time which is causing inconsistency. You can either create a separate list to store the items to be removed and remove the elements after the for loop or use the Iterator methods which allow manipulation of lists while iterating over them. – manjit5190 Mar 25 '20 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.