0

Please help me to get the test class for below class.

public inherited sharing class BI_QuickCloseCompController {
    private static final String CLASS_NAME='BI_QuickCloseCompController';
    private static final String METHOD_NAME='closeSR';
    private static final String CLOSED='Closed';

    @AuraEnabled
    public static Integer getCaseCommentsCount(string caseId){
        return string.isNotBlank(caseId)? [SELECT count() from Casecomments__c where Case_Id__c=:caseId]:0;
    }
    @AuraEnabled
    public static Boolean closeSR(String caseId){
        try{
            if(string.isNotBlank(caseId)){
                string errorMessage='';
                Case sr=new Case(id=caseId,status=CLOSED,SR_Closed_Automatically__c=true);
                if(Schema.SobjectType.Case.isUpdateable()){
                    Database.saveResult saveResultData=Database.update(sr,false);
                    if(saveResultData.isSuccess())
                        return true;
                    else{
                        for(Database.error err:saveResultData.getErrors()){
                            errorMessage=err.getMessage();
                        }
                        UTIL_SLB.throwAuraHandledException(errorMessage);
                    }
                }
            }
        }catch(Exception ecptnWhileClosingSR){
            UTIL_SLB.throwAuraHandledException(ecptnWhileClosingSR.getMessage());
            UTIL_SLB.logHandledException(ecptnWhileClosingSR,BI_UTIL_Constants.Business_Insurance,CLASS_NAME,METHOD_NAME,null,LoggingLevel.ERROR);
        }
        return false;
    }

    @AuraEnabled
    public static boolean saveComment(String caseId,boolean privateFlag,boolean policyFlag, boolean billingFlag, String comment){
        try{
            if(string.isNotBlank(caseId) && string.isNotBlank(comment)){
                String DestionationSystem=UTIL_Common_Constants.EMPTY_VALUE;
                DestionationSystem+=(policyFlag && billingFlag) ? (BI_UTIL_Constants.BI_Target_PolicySystem +UTIL_Common_Constants.SemiColon+ BI_UTIL_Constants.BI_Target_BillingSystem):(policyFlag?BI_UTIL_Constants.BI_Target_PolicySystem:(billingFlag?BI_UTIL_Constants.BI_Target_BillingSystem:UTIL_Common_Constants.EMPTY_VALUE));
                    Casecomments__c casComment = new Casecomments__c(Case_Id__c = caseId,Private__c = privateFlag,Comments__c = comment,Destination_System__c = DestionationSystem) ;
                insert casComment;
                return true;
            }
        }catch(DmlException dmlExcp){UTIL_SLB.extractDMLExcpMsgNThrowAuraHandledException(dmlExcp);}
        return false;
    }
}

Test Class:

@isTest(seeAllData = false)
public class BI_QuickCloseCompControllerTest {
    @testsetup
    static void testData() {
        Case cse = new Case(status='New');
        insert cse;
        Casecomments__c cComments1 = new Casecomments__c();
        cComments1.Comments__c = 'Test123';
        cComments1.Destination_System__c = 'Policy System';
        cComments1.Private__c = true;
        cComments1.Case_Id__c =  cse.Id;
        insert cComments1;

    }
    static testMethod void testSaveCasecomments(){
        List<Casecomments__c> caseComments=[SELECT id,Comments__c,Private__c,Destination_System__c,Case_Id__c FROM Casecomments__c LIMIT 1 ];
        Boolean policySys,billingSys;
        if(string.isNotBlank(caseComments[0].Destination_System__c)){
            policySys=caseComments[0].Destination_System__c.contains('Policy System')?true:false;
            billingSys=caseComments[0].Destination_System__c.contains('Billing System')?true:false;
        }
        caseComments[0].Comments__c+='Update Comment';   
        Casecomments__c updatedComment =BI_QuickCloseCompController.saveComment(caseComments[0].Case_Id__c,caseComments[0].Private__c,policySys,billingSys,caseComments[0].Comments__c);
        System.assertEquals(updatedComment.Private__c, True);
        Casecomments__c upsertedComment =BI_QuickCloseCompController.saveComment(caseComments[0].Case_Id__c,caseComments[0].Private__c,policySys,billingSys,updatedComment.Comments__c+'Upserted Comment'); 
        System.assertEquals(upsertedComment.Private__c,True);
    } 

} 

getting the error Illegal assignment from Boolean to Casecomments__c

Please help me to write the test class for this.

0

this problem arises because you are trying to assign a CaseComments__c variable a boolean value:

Casecomments__c updatedComment =BI_QuickCloseCompController.saveComment();
Casecomments__c upsertedComment =BI_QuickCloseCompController.saveComment();

If you check out your saveComment() method, you will see that it's return value is a boolean and not Casecomments__c

| improve this answer | |
  • Thanks for your quick response, I can see below after that 'Variable does not exist: Comments__c' – Narayana Satish G Jan 21 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.