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
RAMANJINEYULU GOGULARAMANJINEYULU GOGULA 

Can anyone help me writing test class for this code

public with sharing class Rfleet_DEListofUnitOrderRPT_TRG {


public static void onAfterUpdate(Map<Id,CST_Carset__c> mcarsets){

    string cstRectype=null;
    string strCodeconcat1to9=null;
    string strCodeconcat10to18=null;
    List<CST_Carset__c> lsupdateCarSet=new list<CST_Carset__c>();
    for (Rfleet_CountryInfo__c setting : Rfleet_CountryInfo__c.getAll().values()){
        if(setting.Name=='DE'){
            cstRectype=setting.Rfleet_CST_RecordType__c;
        }
    }
    system.debug('$##'+cstRectype);
    Id cstrectyprId = Schema.SObjectType.CST_Carset__c.RecordTypeInfosByName.get(cstRectype).RecordTypeId;

    system.debug('$##'+cstrectyprId);
    
    List<CST_Carset__c> listCarSet = new list<CST_Carset__c>([select Id,Optionscodes10_18__c,Optionscodes1_9__c,(select code__c,servicetype__c from services__r) from CST_Carset__c where id =:mcarsets.keySet()]
       );
    
    for(CST_Carset__c cstoption:listCarSet){
        
         system.debug('cstoption .services__r.size()>>>'+cstoption.services__r.size());
            integer j=0;
            integer k=0;
            integer count=0;
             
        for(Integer i=0;i<cstoption.services__r.size();i++) {
            if(cstoption.services__r[i].servicetype__c=='Option' && count<8) {
               if(cstoption.services__r[i].code__c!=null) { 
                    if(j==0){
                        strCodeconcat1to9=cstoption.services__r[i].code__c+' ';
                        j++;
                    }else{
                        
                    strCodeconcat1to9+=cstoption.services__r[i].code__c+' ';    
                    }   
                    
            }
            count++;    
            System.debug('if count:::'+count);  
           }else if(cstoption.services__r[i].servicetype__c=='Option'){
               
            if(cstoption.services__r[i].code__c!=null) { 
                    if(k==0){
                        strCodeconcat10to18=cstoption.services__r[i].code__c+' ';
                        k++;
                    }else{
                        
                    strCodeconcat10to18+=cstoption.services__r[i].code__c+' ';  
                    }   
                    
            }   
               
           }
           cstoption.Optionscodes1_9__c=strCodeconcat1to9;
           cstoption.Optionscodes10_18__c=strCodeconcat10to18;
        }
    System.debug('Codeconcat1to9:::'+strCodeconcat1to9);
    System.debug('Codeconcat10to18'+strCodeconcat10to18);
    lsupdateCarSet.add(cstoption);
    }
    
    try{
      update lsupdateCarSet;
    }catch(Exception ex) {
     system.debug('## Exception occured::'+ ex);
    }
       
}


}
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi RAMANJINEYULU,
  1.  please check for Test Class Generator App from APP Exchange.Please refer the below link.​https://appexchange.salesforce.com/listingDetail?listingId=a0N3A00000EFozgUAD​​
  2. I will recommend you to start using trailhead to learn about test classeshttps://trailhead.salesforce.com/modules/apex_testing (http:// https://trailhead.salesforce.com/modules/apex_testing)
  3. Please follow below Salesforce Best Practice  Link on Test Classes:-
I hope it will be helpful.

Please mark it as best answer if the information is informative.

Best Regards
Rahul Kumar