Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
792 B
1
Indexable
Never
public class Helper_trigger_acc {
    public static void insertAcc(List<Account> listaAccount){      
        AggregateResult[] CountAccount =[select count(id) contatore, ownerid from account group by ownerid order by count(id)];
        list <account> acc_app = new list <account>();
        for(Account acc: listaAccount)
        {
            integer contatore=0;
            for(integer i=0;i<CountAccount.size();i++){
                if(acc.OwnerId == CountAccount[i].get('owneriD')){
                    contatore = (integer)CountAccount[i].get('contatore');
                    contatore ++;
                }              
            }
            if(contatore > 20){
                acc.ownerid = (ID)CountAccount[0].get('ownerid');
            }
        }
    }
}