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
Jayaramu T 9Jayaramu T 9 

can any one please help me on this?

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CaseTrigger:
execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 02i34000009s1hjAAA;
first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Asset Product Categoryv1.4” process failed.
Give your Salesforce admin these details. This error occurred when the flow tried to update records:
LIMIT_EXCEEDED: System.LimitException: Too many SOQL queries: 101. You can look up ExceptionCode values in the SOAP API Developer Guide.: [] Class.CaseTriggerHandler.updateAssetFields: line 261, column 1 Class.CaseTriggerHandler.onAfterUpdate: line 231, column 1 Trigger. 

could you please follow the below code.
 
Jayaramu T 9Jayaramu T 9
Folloing is the code for above question 
---------------------------------
test class
------------------------
@istest
private class OOBDashboardBatchTest{

  @testSetup static void setup(){
      //Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
       
      /*User u1 = new User(Alias = 'standt', Email='standarduser123562@testorg.com',
                      EmailEncodingKey='UTF-8', LastName='Testing123562', LanguageLocaleKey='en_US',
                      LocaleSidKey='en_US', ProfileId = p.Id,isActive = true,
                      UserEndDate__c = date.today(),managerId=userinfo.getUserId(),
                      TimeZoneSidKey='America/Los_Angeles',UserName='testpermissionsetuser123562@testorg.com',ContactId = null);
      insert u1; 
     system.runAs(u1){*/
      Integer pastYear = Date.today().year() -2;
      Date pastDate = Date.newInstance(pastYear, 01, 01);
      Date currentDate =Date.today();
      String blankVal ='';
  
      Product2 pro= new Product2();
      pro.Product_Group__c='Consumer Products';
      pro.Product_Collection__c='3D Printers';
      pro.Product_Category__c='CubeX';
      pro.Name='Common34';
      insert pro;
 
      Asset as1= new Asset();
      as1.Name='Assettest';
      as1.Ship_Date__c = date.newInstance(2016, 1, 1);
      as1.InstallDate=date.newInstance(2016, 1, 1);
      as1.Product2Id = pro.Id;
      insert as1;

      Issue__c iss=new Issue__c();
      iss.Name='Issuename1';
      iss.Active__c=True;      
      iss.Product_Group__c='Consumer Products';
      iss.Product_Collection__c='3D Printers';
      insert iss;
      
      List<RecordType> i=[Select id,Name from RecordType where Name =:'SalesForce Support'];
      Id k;
     
      RecordType p=i[0];
      k=p.id;
     //Marwin Change, Case has a validation rule where its recordtypeid cannot be Installation Report - 09-20-17
      Id InstReport = [Select id from RecordType where SobjectType = 'Case' and Name =:'Installation Report' limit 1].id;      
      
      Case[] CaseList= new List<Case>();
      for (Integer x=Date.today().year()-2;x<=Date.today().year();x++) {
            Case cs;
            for (Integer CaseMonth=1; CaseMonth<=12;CaseMonth++){ 
                cs =new Case();
                //cs.RecordTypeId= k ; //Changed from InstReport to k
                cs.RecordTypeId = InstReport;
                cs.Status='Open';
                cs.Description='testdescription';
                cs.AssetID=as1.Id;
                if((CaseMonth <= Date.today().month() && x==Date.today().year()) || (x < Date.today().year()))
                cs.Install_Completion_Date__c=date.newInstance(x, CaseMonth, 1);
                //cs.ownerId = u1.id;
                cs.bypassvalidation__c=true;
                CaseList.add(cs);
                system.debug('***CaseInstallDate***'+cs.Install_Completion_Date__c);
            }
            
      }
      system.debug('***CaseList***'+CaseList);
      insert CaseList;
      
      Case_Issue__c[] CaseIssueList= new List<Case_Issue__c>(); 
      Integer casecount=0;
      for (Integer y=Date.today().year()-2;y<=Date.today().year();y++) {
            Case_Issue__c csiss;
            for (Integer MonthCount=1; MonthCount<=12;MonthCount++){ 
                if((MonthCount <= Date.today().month() && y==Date.today().year()) || (y < Date.today().year())){
                    csiss =new Case_Issue__c();
                    csiss.Case__c = CaseList[casecount].id;
                    csiss.Issue__c= iss.id;
                    csiss.Product_Group__c='Consumer Products';
                    csiss.Product_Collection__c='3D Printers';
                    casecount++;
                    CaseIssueList.add(csiss);
                }
            }
            
      }
      system.debug('***CaseIssueList***'+CaseIssueList);
      insert CaseIssueList;
     
      Case cs3=new Case();
      cs3.RecordTypeId= k;
      cs3.Status='Open';
      cs3.Description='testdescription';
      cs3.AssetID=as1.Id;
      cs3.Install_Completion_Date__c=date.newInstance(2017, 1, 1);
      insert cs3;
      
      RPU_OOB_Dashboard_Settings__c custSettings = new RPU_OOB_Dashboard_Settings__c();
      custSettings.Name = 'OOBBatchRunTime';
      custSettings.Dashboard_Run_Date__c = system.now();
      custSettings.Status__c = 'Incomplete';
      insert custSettings;
      
    //}
  }  
 private static testmethod void oobbatchtest(){
    
    test.starttest();
    setup();
    OOBDashboardBatch rs=new OOBDashboardBatch();
    Database.executebatch(rs,200);
    test.stoptest();
    
    //Commented By priya as it is giving Assert Exception error
    //System.assert([select id from RPU_OOB_Report_Summary__c].size() > 0);
 }
    
Apex class
----------------------------
public class CaseTriggerHandler {
 public static List<SelectOption> StageNamePick{get;set;}
 public static boolean isRecursive = false; 
  public CaseTriggerHandler(){
  }
  public static void onBeforeUpdate(Case[] oldRecords, Case[] updatedRecords, Map<ID, Case> oldRecordMap)
  {
    isRecursive = true;
   
  } 
  public static void onBeforeInsert(Case[] newRecords)
  {
  /* Priya case flag */
        for(case cs : newRecords){
            cs.Case_Flag__c = true; 
            cs.Case_Flag_Set_Time__c = system.now();
        }
    List<Case> caselist = updateCase(newRecords);
    Partner_Utility.CasePartner(caselist,UserInfo.getUserId());
   
  }
  public static void onAfterInsert(Case[] newRecords)
  {
    autoAssignCase(newRecords);
    Set<ID> resellset = new Set<ID>();
    List<Case> teamCaseList = new List<Case>();
    for(Case c : newRecords){
        if(c.Reseller__c!=null){
            resellset.add(c.Reseller__c);
            teamCaseList.add(c);
        }
    }
    Set<CaseTeamMember> CaseTeamToAdd = Partner_Utility.getCaseTeamMembers(teamCaseList, resellset);
    List<CaseTeamMember> CaseTeam = new List<CaseTeamMember>();
    CaseTeam.addAll(CaseTeamToAdd);
    insert CaseTeam;
    //Porcess Builder - Case - update asset fields
    updateAssetFields(newRecords);
  }
  public static void onAfterUpdate(Case[] oldRecords, Case[] updatedRecords, Map<ID, Case> oldRecordMap)
  {
    autoAssignCase(updatedRecords);
    // Take new cases, bulkified
    LIST<Case> caselist = Trigger.new;
    // Find all Custom Settings defining default Case Milestones
    LIST<CaseMilestoneSetting__c> CMileSs = [select ID, CaseCriteria__c, MilestoneID__c from CaseMilestoneSetting__C];
    // Loop through each Custom Setting for Case Milestones
    //Fixed LOOp Standard case settings
    Set<Id> mstoneID = new Set<Id>();
      String alias;
      List<CaseMilestone> setmstones ;
    List<CaseMilestone> lp_setmstones = new List<CaseMilestone>();
    for (CaseMilestoneSetting__c CMileS : CMileSs){
        mstoneID.add(CMileS.MilestoneID__c);
        if(CMileS.CaseCriteria__c != null){
            alias = CMileS.CaseCriteria__c;
        }
    }
       
       if(system.test.isRunningTest())
            setmstones = Database.query('Select ID,MilestoneTypeID,CompletionDate FROM CaseMilestone WHERE CaseID IN:caselist AND MilestoneTypeID=:mstoneID AND CompletionDate=NULL');
else
   setmstones = Database.query('Select ID,MilestoneTypeID,CompletionDate FROM CaseMilestone WHERE '+      alias+   'AND CaseID IN:caselist AND MilestoneTypeID=:mstoneID AND CompletionDate=NULL');
                                                       
        // Update the CompletionDate for each CaseMilesone
        for (CaseMilestone updatemstone : setmstones){
            updatemstone.CompletionDate= Datetime.now();
        }
        // Execute the update for all the Milestones in this set
        lp_setmstones.addAll(setmstones);
   
    if(lp_setmstones.size()>0)
    {
        // Execute the update for all the Milestones in this set
        update lp_setmstones;
    }
    Map<ID,Case> installCases = new Map<ID,Case>();
    ID InstallID;
    List<RecordType> installTypes = [SELECT ID, DeveloperName FROM RecordType WHERE sObjectType='Case' AND DeveloperName='Installation_Report' LIMIT 1];
    if(installTypes.size()>0){
        InstallID=installTypes[0].Id;
    }
    for(Case c : updatedRecords){
        if(c.IsClosed && !oldRecordMap.get(c.id).IsClosed && c.RecordTypeID==InstallID && c.AssetId!=null &&c.Status!='Closed As Duplicate'){
            installCases.put(c.AssetId,c);
        }
    }
    Asset_Util.UpdateAssetInstall(installCases);
    //Porcess Builder - Case - update asset fields
    updateAssetFields(updatedRecords);
  }
  public static void updateAssetFields(List<Case> newRecords)
  {
    Map<String, Case> map_AssetIDcase = new Map<String, Case>();
    for(Case c : newRecords)
    {
        map_AssetIDcase.put(c.AssetID, c);
    }
    List<Asset> lst_asset = [SELECT Id, Software_Version__c, Firmware_Version__c, Machine_Status_Up_Down__c, Material__c FROM Asset WHERE Id IN: map_AssetIDcase.keyset() ];
    for(Asset a : lst_asset)
    {
        Case objCase = map_AssetIDcase.get(a.Id);
        if(objCase.Software_Version_Installed__c != a.Software_Version__c)
        {
            a.Software_Version__c = objCase.Software_Version_Installed__c;
        }
        if(objCase.Firmware_Version__c != a.Firmware_Version__c)
        {
            a.Firmware_Version__c = objCase.Firmware_Version__c;
        }
        if(objCase.Material_del__c != a.Material__c)
        {
            a.Material__c = objCase.Material_del__c;
        }
        //else
        //{
            a.Machine_Status_Up_Down__c = objCase.Machine_Status_Up_Down__c;
        //}
    }
    update lst_asset;
  }