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
niranjan eniranjan e 

hi need to about test classes and can anyone help me in writing the test class for the below trigger . started writing test classes.. need to know more about it

trigger case4trigger on User (after insert , after update) 
{
    list<account>acclist = new list<account>();
    list<account>templist = new list<account>();
    Account acc = new Account();
    User u = new User();
    for(User u : trigger.new)
    {
      acclist =  [select Id,OwnerId,Owner.leave__c,Type,Owner.DelegatedApproverId from Account where OwnerId =: u.Id];
            
    }
    for(Account acc : acclist)
    {
        if(trigger.IsInsert)
        {
            if( acc.Owner.leave__c > 90 && acc.Owner.leave__c <180)
        {
            acc.Type = 'Former Client';
            templist.add(acc);
        }
        system.debug('asdf'+templist);
        if(acc.Owner.DelegatedApproverId!= null && acc.Owner.leave__c >180)
        {
            acc.OwnerId = acc.Owner.DelegatedApproverId ;
            templist.add(acc);
        }
        system.debug('qwerty'+templist);
        if(acc.Owner.DelegatedApproverId == null && acc.Owner.leave__c >180)
        {
             acc.Type = 'deactivated';
             templist.add(acc);
        }
        system.debug('zxcv'+templist);
       }
        if(trigger.IsUpdate)
        {
        if( acc.Owner.leave__c > 90 && acc.Owner.leave__c <180)
        {
            acc.Type = 'Former Client';
            templist.add(acc);
        }
        system.debug('asdf'+templist);
        if(acc.Owner.DelegatedApproverId!= null && acc.Owner.leave__c >180)
        {
            acc.OwnerId = acc.Owner.DelegatedApproverId ;
            templist.add(acc);
        }
        system.debug('qwerty'+templist);
        if(acc.Owner.DelegatedApproverId == null && acc.Owner.leave__c >180)
        {
             acc.Type = 'deactivated';
             templist.add(acc);
        }
        system.debug('zxcv'+templist);
        }
    }
      update templist;
        
}
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Niranjan,

May I suggest you please refer the below link for reference on test class best practice. Do You got a chance to check the Test generator app from App Exchange please check the below link Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar