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
David BudimirDavid Budimir 

0% Code Cover Error for Account Trigger

Hey all,

I've been working with the below trigger. I've had no problem executing this in our current Sanbox enivorment (seemed to work fine), but I don't understand why theres no code coverge here at all. Does anything stand out as being obviously wrong? 

Thanks in advance,
David
trigger AccountAfter on Account (after insert, after update){
 
Set<Id> parentAccs = new Set<Id>{};
Map<Id, Integer> childCount = new Map<Id, Integer>{};
 
for (Account a : trigger.new)
if(a.ParentId != null)
parentAccs.add(a.ParentId);  //collect parent ids
 
for(Account acc : [Select Id, ParentId from Account where ParentId IN :parentAccs]){
if(childCount.get(acc.ParentId) == null)
childCount.put(acc.ParentId, 0);  //create a counter for parent
 
childCount.put(acc.ParentId, childCount.get(acc.ParentId) +1); //increment counter
 
}
 
List<Account> accsUpdate = new List<Account>{};
 
for(Id accId : childCount.keySet())
accsUpdate.add(new Account(Id = accId, ChildCount__c = childCount.get(accId))); //set parent counts
 
if(accsUpdate != null && !accsUpdate.isEmpty())
Database.update(accsUpdate); //update parent accounts
}

 
MithunPMithunP
Hi David,

Can you share your test class, so that we can identify the issue in better way.

Best Regards,
Mithun.
Iqrar AhmedIqrar Ahmed
Hi,
David i think you have not written any test class and just viewing default percentage or in other case your trigger is not active first active your trigger then test it using test class.

Best Regards
Iqrar Ahmed