1

My class subtracts the values of child account number fields from the current values of it's parent account number fields in a hierarchy. I need this class to run everytime a child account changes its parent (i.e the parent name field is edited to a new name). I'm attempting to have this trigger compare the old value and the new value of the parent field, when creating the logic for this trigger I keep recieving this error message:

Method does not exist or incorrect signature: void executeSub(Account) from the type Parent_Subtract

Class:

public class Parent_Subtract {
public static void executeSub(List<Account> scope) {

    Id CRecordType = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Customer Account').getRecordTypeId();
    Id DRecordType = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Division Account').getRecordTypeId();
    Id SRecordType = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Site Account').getRecordTypeId();
    Id ERecordType = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Enterprise Account').getRecordTypeId();
    Id DSAccounts = '01270000578681Y';


        List<Id> listIds = new List<Id>();
        Map<Id, Account> parentAccounts = new Map<Id, Account>([SELECT Id, RecordTypeId, Parent_Account__c, Total_CCF__c, Total_Revenue__c, 
                                                                Total_Usage_kWh__c, Account_kw__c, AnnualRev FROM Account WHERE ID In :listIds]);
        Map<Id, Account> newParent = new Map<Id, Account>();
        Set<ID> setParentAcctID = new set<ID>();
        List<Account> listforFinalUpdate = new List<Account>();

    for(Account acc : scope){
        setParentAcctID.add(acc.Parent_Account__c);
    }

        List<account> listParentAcctData = [Select id, Total_CCF__c, Total_Revenue__c, 
                                                                Total_Usage_kWh__c, Account_kw__c, AnnualRevenue 
                                                                FROM account 
                                                                WHERE id =: setParentAcctID];
        for(Account a : listParentAcctData)
        {
            newParent.put(a.id,a);
        }

      for(Account acc: scope)
      {
        Account acct = newParent.get(acc.Parent_Account__c);

            system.debug('acc.Total_Usage_kWh__c:'+acc.Total_Usage_kWh__c);
            system.debug('acc.Total_CCF__c:'+acc.Total_CCF__c);
            system.debug('acc.AnnualRev:'+acc.AnnualRev);
            system.debug('acc.Account_kw__c:'+acc.Account_kw__c);

            acct.Total_Usage_kWh__c -= acc.Total_Usage_kWh__c;
            acct.Total_CCF__c -= acc.Total_CCF__c;
            acct.AnnualRev -= acc.AnnualRev;
            acct.Account_kw__c -= acc.Account_kw__c;

                listforFinalUpdate.add(acct);
        }               

        if(listforFinalUpdate.size() > 0)
        {
          update  listforFinalUpdate;
        }
    }

}

Trigger:

   if(Trigger.isUpdate){
        for(Account acc: Trigger.new){

            Account oldName = Trigger.oldMap.get(acc.Parent_Account__c);

            Account newName = Trigger.newMap.get(acc.Parent_Account__c);


                if(newName != oldName){
                      acct.add(acc);                                                                                                                                 
            }

        }
        Parent_Subtract.executeSub(acct);
    } 

   } 

Am I on the right track with this functionality and does anyone know why I am recieving this message?

5

You're calling a method with a single Account parameter:

Parent_Subtract.executeSub(acct);

but this method is defined to take a List<Account> as its parameter:

public static void executeSub(List<Account> scope) 

This method is bulkified: it is defined to run exactly one DML operation:

update  listforFinalUpdate;

regardless of how many Account records it receives. For this reason you need to be calling it with a List<Account>, not calling it repeatedly in a loop. Your trigger should accumulate a List<Account> inside your for loop, and then make a single call to executeSub() outside the loop.

  • I've updated the trigger and don't receive the error message but values still do not decrement when the field is changed. I'm new to analyzing the debug logs but when I check I see that there is no soql execution for my class when its fired. Is there something else im doing wrong? – Mark Wilson Apr 9 at 18:41
  • @MarkWilson Your class is coded to only run when you change the Parent_Account__c field. Can you be more specific about the issue you are seeing? This may require a separate SFSE question. – David Reed Apr 9 at 20:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.