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
Priya MishraPriya Mishra 

Cyclomatic complexcity

Hi All,

I am facing cylomatic complexcity for the below code pls help me to resolve this it is urgent pls. Thanx In advance


Public static void createOrderandOrderlintiem(List<MedConnect__Repair_Installation_History__c> rAIHList)
{
 
 List<string> repairid = new List<string>();
 Integer count = 0;
 List<string> assiID= new List<string>();
 List<MedConnect__Inventory_Request_Order__c> orderList = new List<MedConnect__Inventory_Request_Order__c>();
 List<String> WOIDList = new List<String>();
 List<MedConnect__Inventory_Request_Order__c> insertorder= new List<MedConnect__Inventory_Request_Order__c>();
 List<MedConnect__Inventory_Order_Line_Item__c> insertorderLineItem= new List<MedConnect__Inventory_Order_Line_Item__c>();
 Map< Integer,MedConnect__Repair_Installation_History__c> repairMap =new Map< Integer,MedConnect__Repair_Installation_History__c>();
 for(MedConnect__Repair_Installation_History__c rh:[select id,Destination_Account__c,Serialized_Part__c,Destination_Inventory__c,Lot_Number_MDSR__r.name,Condition__c,MedConnect__Source_Inventory__c,Lot_Number_MDSR__c,Product_Description_MDSR__c,MedConnect__Operation__c,Return_Flag_MDSR__c,MedConnect__Install_Uninstall__c,MedConnect__Repair_Analysis_And_Parts_Used__r.MedConnect__Work_Order__c,MedConnect__Asset__c,MedConnect__Asset__r.MedConnect__Product__c,Serialized_Part__r.MedConnect__Product__c from MedConnect__Repair_Installation_History__c where id in :rAIHList]){
   if(rh.MedConnect__Operation__c =='Uninstall' && rh.Return_Flag_MDSR__c ==true)
   {
       count++;
     repairid.add(rh.MedConnect__Repair_Analysis_And_Parts_Used__c);
     repairMap.put(count,rh);
     WOIDList.add(rh.MedConnect__Repair_Analysis_And_Parts_Used__r.MedConnect__Work_Order__c);
     
   }
 }
    if(!repairid.isEmpty()){
    List<MedConnect__Inventory_Request_Order__c> InvRequestOrder = [SELECT Id,MedConnect__Account__c, Is_Bulk_Uninstall_from_UI__c,MedConnect__Work_Order__r.MedConnect__Account__c,MedConnect__Work_Order__c FROM MedConnect__Inventory_Request_Order__c
                                                                   WHERE MedConnect__Work_Order__c IN :WOIDList AND Is_Bulk_Uninstall_from_UI__c=true];
    if(!InvRequestOrder.isEmpty()){
        orderList.add(InvRequestOrder.get(0));
    }
    else{
        for(MedConnect__Work_Order__c WO : [SELECT id,MedConnect__Account__c FROM MedConnect__Work_Order__c WHERE ID IN :WOIDList]){
             MedConnect__Inventory_Request_Order__c order = new MedConnect__Inventory_Request_Order__c();
            order.MedConnect__Work_Order__c = WO.Id;
            order.MedConnect__Account__c= WO.MedConnect__Account__c;
            order.Is_Bulk_Uninstall_from_UI__c = true;
            insertorder.add(order);
            orderList.add(order);
        }
         if(insertorder.size()>0){
            Database.SaveResult[] results = Database.insert(insertorder, false);
             for(Database.SaveResult res : results){
                 if(res.isSuccess()){
                 }
             }
    }
    }
 
      //Inserting order line item
        while(count>0){
         MedConnect__Inventory_Order_Line_Item__c oli = new MedConnect__Inventory_Order_Line_Item__c();
          oli.MedConnect__Order_Line_Type__c='Exchange In';
         // oli.MedConnect__Inventory_Request_Order__c=insertorder[0].Id;
          oli.MedConnect__Asset__c=repairMap.get(count).Serialized_Part__c;
          oli.MedConnect__Inventory_Request_Order__c = orderList.get(0).Id;
          oli.MedConnect__Product__c = repairMap.get(count).Serialized_Part__r.MedConnect__Product__c;
          oli.Lot_Batch_MDSR__c = repairMap.get(count).Lot_Number_MDSR__r.name;
          oli.MedConnect__Source_Inventory__c = repairMap.get(count).Destination_Inventory__c;
          oli.MedConnect__Source_Account__c = repairMap.get(count).Destination_Account__c;
           oli.MedConnect__Condition_Source__c = repairMap.get(count).Condition__c;
           
            insertorderLineItem.add(oli);
           count--;
        }
     
      if(insertorderLineItem.size()>0){
     try{
      Database.SaveResult[] results = Database.insert(insertorderLineItem, false);
             for(Database.SaveResult res : results){
                 if(res.isSuccess()){
                 }
             }
        }  
        catch(DMLException e){
       
      }
      }
    }
}
 
SwethaSwetha (Salesforce Developers) 
HI Priya,
Recommend reviewing this related post from past
https://salesforce.stackexchange.com/questions/233367/batchable-schedulable-class-has-cyclomatic-complexity-of-48

https://pmd.github.io/pmd-6.7.0/pmd_rules_apex_design.html#cyclomaticcomplexity

If this information helps, please mark the answer as best. Thank you
Priya MishraPriya Mishra
Thanks for the reply but since i m new to this can u guide me how can i over come from this issue in my code. can u try to modify my code to over come this issue.