+ 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
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; 
      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';
      insert pro;
      Asset as1= new Asset();
      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.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];
     //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;
                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;
      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';
      insert CaseIssueList;
      Case cs3=new Case();
      cs3.RecordTypeId= k;
      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(){
    OOBDashboardBatch rs=new OOBDashboardBatch();
    //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);
  public static void onAfterInsert(Case[] newRecords)
    Set<ID> resellset = new Set<ID>();
    List<Case> teamCaseList = new List<Case>();
    for(Case c : newRecords){
    Set<CaseTeamMember> CaseTeamToAdd = Partner_Utility.getCaseTeamMembers(teamCaseList, resellset);
    List<CaseTeamMember> CaseTeam = new List<CaseTeamMember>();
    insert CaseTeam;
    //Porcess Builder - Case - update asset fields
  public static void onAfterUpdate(Case[] oldRecords, Case[] updatedRecords, Map<ID, Case> oldRecordMap)
    // 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){
        if(CMileS.CaseCriteria__c != null){
            alias = CMileS.CaseCriteria__c;
            setmstones = Database.query('Select ID,MilestoneTypeID,CompletionDate FROM CaseMilestone WHERE CaseID IN:caselist AND MilestoneTypeID=:mstoneID AND CompletionDate=NULL');
   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
        // 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];
    for(Case c : updatedRecords){
        if(c.IsClosed && !oldRecordMap.get(c.id).IsClosed && c.RecordTypeID==InstallID && c.AssetId!=null &&c.Status!='Closed As Duplicate'){
    //Porcess Builder - Case - update asset fields
  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;
            a.Machine_Status_Up_Down__c = objCase.Machine_Status_Up_Down__c;
    update lst_asset;