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
shambavishambavi 

write test class for below class... please

public with sharing class APTS_UOMConversionTriggerHandler implements ITriggerHandler {
  public static Boolean isTriggerDisabled = true;
  public class ApplicationException extends Exception {}
  
  public Boolean isDisabled(){
     try{
         Boolean disabled=false;
         if (TriggerSettings__c.getInstance().UOMConversionTrigger__c) {
           disabled=false;
         } 
         else {
           disabled=isTriggerDisabled;
         }
       return disabled;
     }catch(Exception e) {throw new ApplicationException(e);}
    }
  
    public void beforeInsert(List<SObject> newUOMConversionList){
      /
    } 
 
    public void beforeUpdate(List<SObject> newUOMConversionList, Map<Id, SObject> newUOMConversionMap, List<SObject> oldUOMConversionList, Map<Id, SObject> oldUOMConversionMap){
      
    }
    
    public void beforeDelete(List<SObject> oldUOMConversionList, Map<Id, SObject> oldUOMConversionMap){
      
    }
 
    public void afterInsert(List<SObject> newUOMConversionList, Map<Id, SObject> newUOMConversionMap){
      //Logic to check if the product is active and it is newly inserted.If so will trigger digital pricing
      try{
        onAfterInsertUOMConversion((List<APTS_UOM_Conversion__c>)newUOMConversionList);  
      }catch(DmlException e) {throw new ApplicationException(e);}

    }
  
    public void afterUpdate(List<SObject> newUOMConversionList , Map<Id, SObject> newUOMConversionMap, List<SObject> oldUOMConversionList, Map<Id, SObject> oldUOMConversionMap){
       //Logic to check if the product's isactive field has changed.If so will trigger digital pricing
      try{
        onAfterUpdateUOMConversion((Map<Id, APTS_UOM_Conversion__c>)newUOMConversionMap,(Map<Id, APTS_UOM_Conversion__c>)oldUOMConversionMap);
      }catch(DmlException e) {throw new ApplicationException(e);}
    }
    
    public void afterDelete(List<SObject> oldUOMConversionList, Map<Id, SObject> oldUOMConversionMap){
     
    }
  
    public void afterUndelete(List<SObject> newUOMConversionList, Map<Id, SObject> newUOMConversionMap){
      
    }
    
     public static void onAfterInsertUOMConversion(List<APTS_UOM_Conversion__c> newUOMConversionList){
        try{
         Set<Id> uOMConversionIdsToBeSentToSAPPO=  new Set<Id>();
           for(APTS_UOM_Conversion__c prodTrans:newUOMConversionList){
               if(prodTrans.APTS_Product_Active__c){
                  uOMConversionIdsToBeSentToSAPPO.add(prodTrans.APTS_Product__c);   
               }    
           }
           
           if(!uOMConversionIdsToBeSentToSAPPO.isEmpty()){
             APTS_IntegrationLogHandlerUtility.createIntegrationLogs(uOMConversionIdsToBeSentToSAPPO);      
           }
         }catch(Exception e) {throw new ApplicationException(e);}
     }
   
    public static void onAfterUpdateUOMConversion(Map<Id, APTS_UOM_Conversion__c> newUOMConversionMap,Map<Id, APTS_UOM_Conversion__c> oldUOMConversionMap){
        try{
    Set<Id> uOMConversionIdsToBeSentToSAPPO=new Set<Id>();
        List<Schema.FieldSetMember> relatedFieldSet=new List<Schema.FieldSetMember>();
        relatedFieldSet=APTS_IntegrationLogHandlerUtility.readFieldSet('APTS_UOMFieldsForDigitalProdIntegration','APTS_UOM_Conversion__c');    
        //List<Product2> productsToBeSentToSAPPO=  new List<Product2>();
           for(Id prodId:newUOMConversionMap.keySet()){
               if(newUOMConversionMap.get(prodId).APTS_Product_Active__c && 
                   APTS_IntegrationLogHandlerUtility.checkIfValidToSend(newUOMConversionMap.get(prodId),oldUOMConversionMap.get(prodId),relatedFieldSet)){
                      uOMConversionIdsToBeSentToSAPPO.add(newUOMConversionMap.get(prodId).APTS_Product__c);   
               }    
           }
           
           if(!uOMConversionIdsToBeSentToSAPPO.isEmpty()){
             APTS_IntegrationLogHandlerUtility.checkAndCreateIntegrationLogs(uOMConversionIdsToBeSentToSAPPO);      
           }
        }catch(Exception e) {throw new ApplicationException(e);}
     }
}
Thanks
 
Satish PrajapatSatish Prajapat

Hello Shambavi,
Please apply some efforts, still if get any problem than share your problems.

Thanks,
Satish.

shambavishambavi
Thanks for giving reply ... please help me on this.. i am new to salesforce and i am in learning stage...


Thanks 
Satish PrajapatSatish Prajapat

Hey Shambavi,

No worries if you newbie, If you want learn so I can help you. But I want that you apply efforts.
You can write apex logic, similarly you have to write the Test class logic, I will help you in this.
Please follow the below code:

@isTest 
private class MyTestClass 
{
    static testMethod void m1() 
    {
           ///Shambavi, please create object of class for which you are writing test clsss.
           APTS_UOMConversionTriggerHandler obj = new APTS_UOMConversionTriggerHandler();
           //Call all the method of that class.
           obj.isDisabled();
           List<sObject> sObjectList = new List<sObject>();
           sObject s1 = Schema.getGlobalDescribe().get('Account').newSObject();
           sObject s2 = Schema.getGlobalDescribe().get('Contact').newSObject();
           sObject s3 = Schema.getGlobalDescribe().get('Opportunity').newSObject();
           sObjectList.add(s1);
           sObjectList.add(s2);
           sObjectList.add(s3);
           //pass List here as parameter.
           obj.beforeInsert(sObjectList);//crete dummy record of type List<sObject> and pass it into the method.

           obj.beforeUpdate(pass parameter here);
           obj.beforeDelete(pass parameter here);
           obj.afterInsert(pass parameter here);
           obj.afterInsert(pass parameter here);
           obj.afterUpdate(pass parameter here);
           obj.afterDelete(pass parameter here);
           obj.afterUndelete(pass parameter here);
           obj.onAfterInsertUOMConversion(pass parameter here);
           obj.onAfterUpdateUOMConversion(pass parameter here);
    }
}


I hope this is helpful for you,

still you are getting error than you can contact me.
Thanks,

Satish.