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
virkvirk 

Automate the retreiving the data from log table and calling the respective method

Can someone help me in writing a code snippet for these methods:

public static void hierarchyAccountDeploiment(List<Account> accs, Map<Id, Account> oldMap)
    {
        List<Id> accIds = new List<Id>();
        Boolean hasHierarchy;
        List<Account> toUpdate = new List<Account>();

        for (Account a : accs)
            if (a.RecordTypeID == '012D00000002qdE' && a.R_seau_int_gr__c == true && a.Etat_relation_GEO__c == 'Déploiement' && (oldmap == null || oldMap.get(a.Id).Etat_relation_GEO__c != 'Déploiement'))
            {
                hasHierarchy = true;
                accIds.add(a.id);
                while (hasHierarchy)
                {
                    List<Account> res = [SELECT id, Etat_relation_GEO__c FROM Account WHERE Etat_relation_GEO__c != 'Terminé' AND parentId IN :accIds];
                    accIds.clear();
                    if (res == null || res.size() == 0)
                        hasHierarchy = false;
                    for (Account aa : res)
                    {
                        accIds.add(aa.id);
                        toUpdate.add(aa);
                    }
                }
            }
        for (Account a : toUpdate)
            a.Etat_relation_GEO__c = 'Déploiement';
        if (toUpdate != null && toUpdate.size() > 0)
            update toUpdate;
    }


    public static void hierarchyAccountTerminer(List<Account> accs, Map<Id, Account> oldMap)
    {
        List<Id> accIds = new List<Id>();
        Boolean hasHierarchy;
        List<Account> toUpdate = new List<Account>();

        for (Account a : accs)
            if (a.RecordTypeID == '012D00000002qdE' && a.R_seau_int_gr__c == true && a.Etat_relation_GEO__c == 'Terminé' && (oldmap == null || oldMap.get(a.Id).Etat_relation_GEO__c != 'Terminé'))
            {
                hasHierarchy = true;
                accIds.add(a.id);
                while (hasHierarchy)
                {
                    List<Account> res = [SELECT id, Etat_relation_GEO__c FROM Account WHERE parentId IN :accIds];
                    accIds.clear();
                    if (res == null || res.size() == 0)
                        hasHierarchy = false;
                    for (Account aa : res)
                    {
                        accIds.add(aa.id);
                        toUpdate.add(aa);
                    }
                }
            }
        for (Account a : toUpdate)
            a.Etat_relation_GEO__c = 'Terminé';
        if (toUpdate != null && toUpdate.size() > 0)
            update toUpdate;
    }

public static void terminerFilByAccount(List<Account> accs)
    {
        List<Id> accIds = new List<Id>();
        List<Contexte__c> toUpdate = new List<Contexte__c>();

        for (Account a : accs)
            if (a.Etat_relation_GEO__c == 'Terminé')
                accIds.add(a.id);
        for (Contexte__c fil : [SELECT id, Statut__c FROM Contexte__c WHERE (PART_ETX__c IN :accIds OR PART_Siege__c IN :accIds OR PART_CA__c IN :accIds) AND Statut__c != 'Terminé'])
            if (allowedToChangeStatus(fil.Statut__c, 'Terminé'))
            {
                fil.Statut__c = 'Terminé';
                toUpdate.add(fil);
            }
        if (toUpdate != null && toUpdate.size() > 0)
            update toUpdate;
    }

I am calling these methods from a trigger

Trigger method

if (trigger.isAfter && (trigger.isInsert || trigger.isUpdate))
    {
        UpdateStatus.hierarchyAccountDeploiment(trigger.new, trigger.oldMap);
        UpdateStatus.hierarchyAccountTerminer(trigger.new, trigger.oldMap);
        UpdateStatus.terminerFilByAccount(trigger.new);
    }

I want to autmate this. If there is a batch callling this trigger it should check the log table of thousands of records for the fields change in status and run the soql, call the respective methods and empty the table of satus change.

I am totally new to this kind of coding any sort of help will be kind.

Thanks,