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
Sri 7Sri 7 

any one of you please help me to write test class for below code handler

    public static void iqId(List<Account> iqList){
        
        for(Account eachAccount: iqList){
            if(eachAccount.IQ_ID__c!=null){
                system.debug('IQ_ID__c');
                if(!eachAccount.Sales_Ops__c){
                    
                    eachAccount.C_Name__c=eachAccount.Ultimate_Parent__c;
                    eachAccount.H_ID__c=eachAccount.Ultimate_Parent_Id__c;
                } else {
                    if (eachAccount.ParentId != null){
                        Map<string,string> ultimateDetails = getultimate(eachAccount.ParentId);
                        List<string> ultimateId = new List<string>();
                        ultimateId.addAll(ultimateDetails.keyset());
                        eachAccount.C_Name__c=ultimateDetails.values()[0];
                        eachAccount.H_ID__c=ultimateId[0];
                    }
                }
            }
        }
    }
    public static Map<string, String> getultimate(string parentAccount){
        boolean isSFDCUltimate = true;
        Map<string, string> ultimateParent = new Map<string, string>();
        while(isSFDCUltimate){
            Account temp = [select Id, Name, ParentId, IQ_ID__c from Account Where Id=:parentAccount];
            if (temp.ParentId==null){
                ultimateParent.put(temp.IQ_ID__c, temp.Name);
                break;
            }else {
                parentAccount=temp.ParentId;
            }
        }
        return ultimateParent;
    }
Prem RPrem R
Hi, 

Is it trigger handler ? or you are invoking this method from Visualforce page?

Thanks,
Prem
Sri 7Sri 7
no it is TriggerHandler
Niraj Kr SinghNiraj Kr Singh
Hi Sri,

There is an issue with your code you fix it as well.
It will throw an exception when going to process more than 100 accounts and that exception will be:
Excep:> System.LimitException: Too many SOQL queries: 101

You are calling this inside your iqId() method
Map<string,string> ultimateDetails = getultimate(eachAccount.ParentId);

That is running under for loop of account and this method getultimate() is having SOQL.

thanks