You need to sign in to do that
Don't have an account?
3C
Trigger incorrectly updating records
We have a trigger that is meant to update account records to customer (meaning they have active assets) or location (no active assets). This is the relevant part of the associated class. In the final lines, Type is supposed to be updated to Location only if there are no active assets. However, in testing it is updating to Location whenever we deactivate any asset on an account, even if there are other assets that are still active. What could be causing this?
List<Account> accountsToUpdate = new List<Account>(); for(String accountID: mapAccountToAssets.keySet()) { Account loc = new Account(ID = accountID); Boolean hasOnMaintenanceAssets = false; Boolean isLocation = false; for(Customer_Asset__c ca: mapAccountToAssets.get(accountID)) { if(ca.Account__r.RecordTypeID == AccountServices.recordTypesNameMap.get(Constants.ACCOUNT_RECORD_TYPE_FACILITY).ID) isLocation = true; if(ca.Maintenance_Status__c == Constants.STATUS_ON_SUBSCRIPTION && ca.Annual_Maintenance__c > 0) { hasOnMaintenanceAssets = true; loc.Type = 'Customer'; break; } } if(!hasOnMaintenanceAssets) { if(isLocation) loc.Type = 'Location'; } accountsToUpdate.add(loc); } update accountsToUpdate; }
Hoping I've understood the questions correctly..