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

Unable to increase Test Coverage.. Pls help!!!!!

I have written a trigger to display and error if user try to create more than one record for an object.

Its working fine,


trigger ENT_Trigger_OnlyOneFund on Fund__c(before insert)

integer count = [select count() from Fund__c]; 

for(Fund__c L : trigger.New) 

  L.addError('There can be only one record of Fund '); 



Than I wrote a test class for the same which is showing me 13% test covegare. 


private class TestOnlyOneFund  
    static testMethod void validateFund()
     Account a=new Account(Name='Test', AccountNumber='Test1');
     insert a;
    Fund__c c= new Fund__c(Fund_Name__c='test',;
     insert c;

Please help what code I should add to increase test coverage for this class.




You have only created one CDFI Fund Record, so it doesn't go beyond count > 0 when the trigger is executed from the test coverage.


Simply create another record for CDFI Fund and then you'll be able to cover most of your code.


Hi Vishal,


I tried adding another record too but its giving me error which is from my trigger itself. i.e. " There can be only one record of CDFI Fund and its already existing".


Any other workaround for the same?


This is the normal behavior of the trigger posted. To check the error put the second insert statement inside try-catch block.