• Nishit Mistryyy
  • NEWBIE
  • 40 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 4
    Replies
CaseTrigger.txt
trigger CaseTrigger on Case (before update, After Insert, before insert,After update){
    //before Triggers
    if(Trigger.isBefore){
        //before insert
        if(Trigger.isInsert){
            CaseTriggerHandler.validateEmail(Trigger.New);
            CaseTriggerHandler.registerOrNot(Trigger.New);
            if(CaseTriggerHelper.isCaseInserted == false){
                CaseTriggerHandler.populateTATOnCase(Trigger.New);
                CaseTriggerHandler.populateEntitlementOnCase(Trigger.New);
                CaseTriggerHandler.getCaseCategories(Trigger.New,true);
                CaseTriggerHandler.validateCaseCreationWithinTAT(Trigger.New);
                CaseTriggerHandler.validateTATBreachedCaseCreation(Trigger.New);
                CaseTriggerHandler.populateEmailOnCase(Trigger.New);
                CaseTriggerHandler.complaintsproritycheck(Trigger.New);
            }
            
            //CTSTMetadataHandler.setPriorityOnCaseInsert(trigger.new);
        }
        
        //before update
        if(Trigger.isUpdate){
            if(CaseTriggerHelper.isCaseUpdated == false){
                CaseTriggerHandler.updateSTatusAndFlags(Trigger.New, Trigger.oldMap);
                CaseTriggerHandler.populateAccountandServicebranchOnCase(Trigger.New);
                CaseTriggerHandler.updateEscalationMails(Trigger.New);
                CaseTriggerHandler.autoCloseMilestone(Trigger.New);
                CaseTriggerHandler.populateEntitlementOnCase(Trigger.New);        
                CaseTriggerHandler.getCaseCategories(Trigger.New,false); 
                //CaseTriggerHandler.updateQueueAssignedDate(Trigger.new, false);
                CaseTriggerHandler.PopulateClosedBy(Trigger.New);
                CaseTriggerHandler.complaintsproritycheck(Trigger.New);
                if(CaseTriggerHelper.assignmentDetails == false){
                    CaseTriggerHandler.updateQueueAssignedDate(Trigger.New);
                }
            }
        }
    }
    //After triggers
    else if(Trigger.isAfter){
        //after insert
        if(Trigger.isInsert){

            if(CaseTriggerHelper.isCaseInserted == false){
                /**DON't REMOVE OR COMMENT THIS METHOD Added BY Pratap*/
                CaseTriggerHandler.createCaseCustomDetail(Trigger.new);
                 /**DON't REMOVE OR COMMENT THIS METHOD Added BY Pratap*/

                CaseTriggerHandler.postNonKYCUpdateAPI(Trigger.New);         
                CaseTriggerHandler.postContactUpdateAPI(Trigger.new, null);
                CaseTriggerHandler.populateLoanOnCase(Trigger.new);
                //Added by PJ date 12 Oct 23
                //CaseTriggerHandler.sendCaseCreationSMS(Trigger.New);
                //addded by PJ
                 CaseSMShandler.sendCaseCreationSMS(Trigger.new);
                 //Ended by PJ


                //CaseTriggerHandler.sendCaseCreationSMS(Trigger.New,'New');
                CaseTriggerHandler.complaintsproritycheck(Trigger.New);
                CaseTriggerHandler.updateTopManagementFlag(Trigger.newMap.keySet());
                //CaseTriggerHandler.caseOwnerAfterInsertHelper(Trigger.New);
                if(Boolean.valueOf(System.label.Run_csOutbondFlag)){
                    CaseTriggerHandler.csOutbondFlag(Trigger.New);
                }
            }
            CaseTriggerHandler.callCaseAssignment(Trigger.newMap);
        }
        
        //after update
        if(Trigger.isUpdate){
            if(CaseTriggerHelper.isCaseUpdated == false){
                CaseTriggerHandler.postNonKYCUpdateAPI(Trigger.New);    
                CaseTriggerHandler.populateLoanOnEmailMessageOfCase(Trigger.new, trigger.oldMap);
                CaseTriggerHandler.sendCaseCreationUpdSMS(Trigger.new,trigger.oldMap);
                //CaseTriggerHandler.sendCaseClosureSMS(Trigger.new,trigger.oldMap);
                //addded by PJ
                CaseSMShandler.sendCaseClosureSMS(Trigger.new,trigger.oldMap);
                //CaseSMShandler.sendCaseCreationSMSOnUpdate(Trigger.new,trigger.oldMap);
                 //Ended by PJ
                CaseTriggerHandler.sendDocOnEmail(Trigger.new);
                CaseTriggerHandler.caseARforPendingWithCustomer(Trigger.new, trigger.oldmap);
                CaseTriggerHandler.complaintsproritycheck(Trigger.New);
            }
            //CaseTriggerHandler.validateExcludedCase(Trigger.new, Trigger.oldMap);
            CaseTriggerHandler.vehicleUpdateAPIcall(Trigger.new, Trigger.oldMap);
            CaseTriggerHandler.postContactUpdateAPI(Trigger.new, Trigger.oldMap);
        }
    }
}

CaseTriggerHandler.apxc
public class CaseTriggerHandler {
public static Boolean isCaseInserted = false;
//Helper method to check priority of Complaints CTST.
    public static void complaintsproritycheck(List<Case> newCaseList){
        Id caseTypeGenericTemplate = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Generic Template').getRecordTypeId();
        Map<Case, CaseCategoryMetadata__c> caseCategoriesMap = new Map<Case, CaseCategoryMetadata__c>();
        Set<String> caseCategorySet = new Set<String>();
        Set<String> categorySet = new Set<String>();
        Set<String> subcategorySet = new Set<String>();
        Set<String> subsubcategorySet = new Set<String>();
        Set<String> productTypeSet = new Set<String>();
        DateTime startDate = DateTime.newInstance(2023, 11, 16,12,0,0);
        
        String dynamicCMDQuery = '';
        
        for(Case caseRec : newCaseList){
            if(caseRec.Case_Category__c=='Complaint' && caseRec.RecordTypeId==caseTypeGenericTemplate){
                if(!String.isBlank(caseRec.Product_Type__c)){
                    productTypeSet.add(caseRec.Product_Type__c);
                }
                if(!String.isBlank(caseRec.Case_Category__c)){
                    caseCategorySet.add(caseRec.Case_Category__c);
                }
                if(!String.isBlank(caseRec.Category__c)){
                    categorySet.add(caseRec.Category__c);
                }
                if(!String.isBlank(caseRec.Sub_Category__c)){
                    subcategorySet.add(caseRec.Sub_Category__c);
                }
                if(!String.isBlank(caseRec.Sub_Sub_Category__c)){
                    subsubcategorySet.add(caseRec.Sub_Sub_Category__c);
                }
            } else{
                return;
            }

            
        }
        
        //Set<Case_Category_Metadata__mdt> caseCategoryCMDSet = new Set<Case_Category_Metadata__mdt>();
        Set<CaseCategoryMetadata__c> caseCategoryCMDSet = new Set<CaseCategoryMetadata__c>();
        if((productTypeSet.size()>0) &&
           (caseCategorySet.size()>0) &&
           (categorySet.size()>0) &&
           (subcategorySet.size()>0)
          ){
              dynamicCMDQuery += 'select Product_Type__c, Case_Category__c, Category__c, Sub_Category__c, Sub_Sub_Category__c, Escalation_2_Business_Days__c, Priority__c from CaseCategoryMetadata__c ';
              dynamicCMDQuery += 'where Product_Type__c IN: productTypeSet AND Case_Category__c IN: caseCategorySet AND Category__c IN: categorySet AND Sub_Category__c IN: subcategorySet AND isActive__c = true AND Priority__c=\'High\'';
              if(subsubcategorySet.size()>0){
                  dynamicCMDQuery += 'AND Sub_Sub_Category__c IN: subsubcategorySet';
              }
          }
        
        //List<Case_Category_Metadata__mdt> caseCategoryCMD = new List<Case_Category_Metadata__mdt>();
        List<CaseCategoryMetadata__c> caseCategoryCMD = new List<CaseCategoryMetadata__c>();
        if(!String.isBlank(dynamicCMDQuery)){
            caseCategoryCMD = Database.query(dynamicCMDQuery);   
        }
        System.debug('caseCategoryCMD: '+caseCategoryCMD); 
        if(!Test.isRunningTest()){
        for(Case caseRec : newCaseList){
            if(caseCategoryCMD.size() == 0){
                if(caseRec.CreatedDate > startDate){
                    caseRec.addError('Selected Category is not a part of the complaint case type');
                }
            }}    
        }

    }
public static void updateTopManagementFlag(Set<Id> newCasesids){
        List<case> caseListupdate = [select id, owner.name from case where id IN :newCasesids ];
        for(Case caseRec : caseListupdate){
            if(caseRec.Owner.name == 'Top Management Escalation bucket'){
                caseRec.Top_Management_Flag__c = 'Yes';
            }else{
                caseRec.Top_Management_Flag__c = 'No';
            }
        }
        update caseListupdate;
    }

Getting an below error
CaseTrigger: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 5001s000008uj8GAAQ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Selected Category is not a part of the complaint case type: [] Class.CaseTriggerHandler.updateTopManagementFlag: line(update caseListupdate;)
Trigger.CaseTrigger: line 61, column 1

Hello Team,
I want to develop a Aging report on Case history report type
This is the requirement.

Consider a case which is initially present in Queue (Case Owner) A ... lets say this case was present in queue A for 2 days. Then it was transferred to Queue B and it stayed under that queue for 3 days.

So I want to create such a report where I can classify the cases based on number of days they were present under certain queue.
Classification is ;;;; 0-2, 3-8, 9-12 & 13-15 days.

Please help me / guide me to create this report in salesforce.

Hello,
I have created one flow in salesforce where at the end of the flow a new record is being created with fields as Category, Sub Category, Comments and the Date&Time at which the record is being created......


I want to fetch those values into a lightning web component....
I have also created one lightning web component (TABLE) where I will display all the values of the record created everytime.

So everytime when a record is created the table will get updated with values of the updated record

So what would be the solution to fetch the values from a flow and then display them into the lightning web component(table).

 

I have a class that selects target date and case id from an object CaseMilestone and then it puts it into a list and then it mappes the target date as the milestone date... I want to write a test class for it but my test class only covers 57% of the code... It is unable to enter the IF condition present in the main class

THE CODE FOR THE CLASS IS:
public class DisplayCaseMilestoneDateCtrl {
    @AuraEnabled(cacheable=true)
    public static string getCaseMilestoneDate(String caseId){
        List<CaseMilestone> cmList = [SELECT targetDate,caseId FROM CaseMilestone where caseId =: caseId];
        if(cmList != null && cmList.size() > 0){
            DateTime dt = cmList[0].targetDate;
            string milestoneDate = dt.format('d-MMM-yyyy hh:mm a');
            return milestoneDate;
        }
        else{
            return 'No milestone date to show.';
        }
    }
}

 

And THE CODE FOR THE TEST CLASS WITH 57% code coverage is:
@isTest
public class DisplayCaseMilestoneDateCtrlTest {
    static testmethod void testmethod1() {
        List<Id> idss = new List<Id>();
        CaseMilestone cms = new CaseMilestone();
        idss.add(cms.CaseId);
        Test.startTest();
        DisplayCaseMilestoneDateCtrl.getCaseMilestoneDate('500N000000J0MkfIAF');
        Test.stopTest();
        
    }
    
}

I have a class called MilestoneUtils and i want to write a test class for it
The code for the class is:
public class MilestoneUtils {

    public static void completeMilestone(List<Id> caseIds, DateTime complDate) {  
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
            from CaseMilestone cm
            where caseId in :caseIds 
            and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
        for (CaseMilestone cm : cmsToUpdate){
            cm.completionDate = complDate;
            }
        update cmsToUpdate;
        }
    }
}

//and cm.MilestoneType.Name=:milestoneName

I have a batch class in which fields are updated from CWL fields to standard fields. I want to write the test class for it with 100% code coverage.

The code for the class is :
/**
*@Class Name - BatchUpdateCTSTfieldsFromCWLCTSTfields
*@Created on: 07/Sept/2020
*@Modified on: 
*@Modified Reason: 
*@description - copying CTST Data from CWL fields to Non CWL fields 
*/
global class BatchUpdateCTSTfieldsFromCWLCTSTfields implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC){
      
        string recordTypeName = 'Case without Lan';
        string caseId = '500p0000007m8ItAAI';
        //string query = 'SELECT Id, CWL_Case_Category__c, CWL_Category__c, CWL_Customer_Name__c, CWL_Loan_Number__c, CWL_Sub_Category__c, CWL_Sub_Sub_Category__c, Case_Category__c, Category__c, Sub_Category__c, Sub_Sub_Category__c, RecordType.name FROM Case where RecordType.name =:recordTypeName and Id =: caseId ';      
        string caseCategory = '';
        string query = 'SELECT Id,CaseNumber,Product_Type__c, CWL_Customer_Name__c, CWL_Loan_Number__c, CWL_Case_Category__c, Case_Category__c, CWL_Category__c, Category__c,   CWL_Sub_Category__c, Sub_Category__c, CWL_Sub_Sub_Category__c, Sub_Sub_Category__c, RecordType.name FROM Case where RecordType.name =:recordTypeName and Case_category__c =:caseCategory ';      
            system.debug('#####query@@@'+ query);
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Case> CWLCaseList){
        system.debug('CWLCaseList:' + CWLCaseList.Size());
        try{
            List<Case> caseList = new List<Case>();
            
            for (Case caseRec : CWLCaseList){
                if(caseRec.RecordType.name == 'Case without Lan'){
                    if(caseRec.Product_Type__c == '' ||  caseRec.Product_Type__c == NUll){
                        caseRec.Product_Type__c = 'Others';
                    }
                       caseRec.Case_Category__c = caseRec.CWL_Case_Category__c;
                       caseRec.Category__c = caseRec.CWL_Category__c;
                       caseRec.Sub_Category__c = caseRec.CWL_Sub_Category__c;
                       caseRec.Sub_Sub_Category__c = caseRec.CWL_Sub_Sub_Category__c;
                       caseList.add(caseRec);
                   }
            }
            
            CaseTriggerHelper.isCaseUpdated = true;
            CaseTriggerHelper.isCaseInserted = true;
            system.debug('@@@@@@@@@@@@caseList:@@@@@@@@@@@@' + caseList);
            Database.SaveResult[] updatedCase= Database.update(caseList,false);
            system.debug('@@@@@@@@@@@@updatedCase:@@@@@@@@@@@@' + updatedCase);
            for (Database.SaveResult sr : updatedCase) {
                for(Database.Error err : sr.getErrors()) {
                    ErrorLogCls.SaveError(err.getStatusCode() + ' : ' + err.getMessage() +' : Case fields that affected this error: ' + err.getFields(),'error:' + err, 42,'execute', 'BatchUpdateCTSTfieldsFromCWLCTSTfields','code');
                }
            }
        }
        catch(Exception ex){
            ErrorLogCls.SaveError(ex.getMessage(),ex.getStackTraceString(), ex.getLineNumber(),'execute', 'BatchUpdateCTSTfieldsFromCWLCTSTfields','catch block');
        }
    }  
    
    global void finish(Database.BatchableContext BC){ }
}

I have a class and I want to write a test class for it, The code of the class is as follows:

public class MilestoneUtils {

    public static void completeMilestone(List<Id> caseIds, DateTime complDate) {  
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
            from CaseMilestone cm
            where caseId in :caseIds 
            and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
        for (CaseMilestone cm : cmsToUpdate){
            cm.completionDate = complDate;
            }
        update cmsToUpdate;
        }
    }

There is one case which had a milestone of 5 days, the TAT of the case had breached so the case owner should be notified through case escalation emails.

There are two escalations to two different people, but the first user did not receive any email, and directly the second mail escalated and that also to directly a third person, so how to check from the email logs that whether the escalation rule worked properly or not?

And why did the second escalation executed directly and second escalation mail got to a third person???

I have one class that is defined, I want to write a test class for it with an EXPLANATION!!
The code for the apex class is :

global class ScheduleToUpdateMilestoneTargetdate implements schedulable{
    global void execute(Schedulablecontext sc)
    {
        BatchClassToUpdateCaseObject cases=new BatchClassToUpdateCaseObject();
        if(!Test.isRunningTest()){
            Database.executeBatch(cases,200);
        }
    }  
}

I have a class and I am trying to write a test class for it here is the code:
global class BatchMassDeleteDraftCaseRecs Implements Database.batchable<sobject>{
    
    global BatchMassDeleteDraftCaseRecs(){
         
    }
    global Database.QueryLocator start(Database.BatchableContext BC){
        
        String statusDraft = 'Draft';
        String statusNew = 'New';
        String statusClosed = 'Closed';
        return Database.getQueryLocator('SELECT Id, Status FROM Case WHERE (Status = :statusDraft OR Status = :statusNew OR Status = :statusClosed) and FileUploadFlag__c =true');
    }
    global  void execute(Database.BatchableContext BC,List<SObject> scope){
        delete scope;
    }
    global void finish(Database.BatchableContext BC){
    }
}
I have a code where I am getting the year, month and date from the date which is passed as a string, i need to write the test class for it. 
Here is the class:
public class DateHelper {
    
    /*
        Integer year_;
        Integer month_;
        Integer day_;
    */
    
    public static datetime Get_Date_FromYYYYMMDD(String DateString)
    {
        Integer year =  integer.valueof(DateString.substring(0, 4));
        Integer month = integer.valueof(DateString.substring(5, 7));
        Integer day = integer.valueof(DateString.substring(8, 10));
        
        return Date.newInstance(year, month, day);
    }
    
    /*
    public date GetFromYYYYMMDD_P
    {
        get
        {
            
            return Date.today();
        }
    }*/

}
Hello,
I have a apex class defined as ContactListController, this class basically gets the list of contacts from my salesforce developer org. I want to write the test class for it.
The code is: 
public class ContactListController {
        
    @AuraEnabled
    public static List<Contact> getContactList(List<Id> accountIds) {
        // Getting the list of contacts from where Id is in accountIds
                List<Contact> contactList = [SELECT Id, Name, Email FROM Contact WHERE AccountId in :accountIds];
                // Returning the contact list
        return contactList;
    }
}

I have build a flow, which i want to run in the future date, but I want to check it right now whether it is working properly or not?

So i want to change the date so that I can test my flow, and also is it possible to change the date multiple times???

I have a class called MilestoneUtils and i want to write a test class for it
The code for the class is:
public class MilestoneUtils {

    public static void completeMilestone(List<Id> caseIds, DateTime complDate) {  
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
            from CaseMilestone cm
            where caseId in :caseIds 
            and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
        for (CaseMilestone cm : cmsToUpdate){
            cm.completionDate = complDate;
            }
        update cmsToUpdate;
        }
    }
}

//and cm.MilestoneType.Name=:milestoneName

I have a batch class in which fields are updated from CWL fields to standard fields. I want to write the test class for it with 100% code coverage.

The code for the class is :
/**
*@Class Name - BatchUpdateCTSTfieldsFromCWLCTSTfields
*@Created on: 07/Sept/2020
*@Modified on: 
*@Modified Reason: 
*@description - copying CTST Data from CWL fields to Non CWL fields 
*/
global class BatchUpdateCTSTfieldsFromCWLCTSTfields implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC){
      
        string recordTypeName = 'Case without Lan';
        string caseId = '500p0000007m8ItAAI';
        //string query = 'SELECT Id, CWL_Case_Category__c, CWL_Category__c, CWL_Customer_Name__c, CWL_Loan_Number__c, CWL_Sub_Category__c, CWL_Sub_Sub_Category__c, Case_Category__c, Category__c, Sub_Category__c, Sub_Sub_Category__c, RecordType.name FROM Case where RecordType.name =:recordTypeName and Id =: caseId ';      
        string caseCategory = '';
        string query = 'SELECT Id,CaseNumber,Product_Type__c, CWL_Customer_Name__c, CWL_Loan_Number__c, CWL_Case_Category__c, Case_Category__c, CWL_Category__c, Category__c,   CWL_Sub_Category__c, Sub_Category__c, CWL_Sub_Sub_Category__c, Sub_Sub_Category__c, RecordType.name FROM Case where RecordType.name =:recordTypeName and Case_category__c =:caseCategory ';      
            system.debug('#####query@@@'+ query);
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Case> CWLCaseList){
        system.debug('CWLCaseList:' + CWLCaseList.Size());
        try{
            List<Case> caseList = new List<Case>();
            
            for (Case caseRec : CWLCaseList){
                if(caseRec.RecordType.name == 'Case without Lan'){
                    if(caseRec.Product_Type__c == '' ||  caseRec.Product_Type__c == NUll){
                        caseRec.Product_Type__c = 'Others';
                    }
                       caseRec.Case_Category__c = caseRec.CWL_Case_Category__c;
                       caseRec.Category__c = caseRec.CWL_Category__c;
                       caseRec.Sub_Category__c = caseRec.CWL_Sub_Category__c;
                       caseRec.Sub_Sub_Category__c = caseRec.CWL_Sub_Sub_Category__c;
                       caseList.add(caseRec);
                   }
            }
            
            CaseTriggerHelper.isCaseUpdated = true;
            CaseTriggerHelper.isCaseInserted = true;
            system.debug('@@@@@@@@@@@@caseList:@@@@@@@@@@@@' + caseList);
            Database.SaveResult[] updatedCase= Database.update(caseList,false);
            system.debug('@@@@@@@@@@@@updatedCase:@@@@@@@@@@@@' + updatedCase);
            for (Database.SaveResult sr : updatedCase) {
                for(Database.Error err : sr.getErrors()) {
                    ErrorLogCls.SaveError(err.getStatusCode() + ' : ' + err.getMessage() +' : Case fields that affected this error: ' + err.getFields(),'error:' + err, 42,'execute', 'BatchUpdateCTSTfieldsFromCWLCTSTfields','code');
                }
            }
        }
        catch(Exception ex){
            ErrorLogCls.SaveError(ex.getMessage(),ex.getStackTraceString(), ex.getLineNumber(),'execute', 'BatchUpdateCTSTfieldsFromCWLCTSTfields','catch block');
        }
    }  
    
    global void finish(Database.BatchableContext BC){ }
}

I have build a flow, which i want to run in the future date, but I want to check it right now whether it is working properly or not?

So i want to change the date so that I can test my flow, and also is it possible to change the date multiple times???