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
Devadarsi Devasis 9Devadarsi Devasis 9 

Can Anyone help me in solving the error in the Test Class: Illegal assignment from Integer to List<Case>

dsiplaycases.apex

public with sharing class dsiplaycases {
       @AuraEnabled
       public static Integer TotalRecords(){
           return [Select count() from Case];
       }
    @AuraEnabled(cacheable=true)
       public static List<Case> getCaseList(){
           return [select id, casenumber, subject,acc__c,reason,status,origin,con__c from case WITH SECURITY_ENFORCED ];
       }
       @AuraEnabled(cacheable=true)
       public static List<Case> getCaseList(Integer v_Offset, Integer v_pagesize){
           return [select id, casenumber, subject,acc__c,reason,status,origin,con__c from case limit :v_pagesize OFFSET :v_Offset];
       }

       @AuraEnabled(cacheable=true)
       public static Integer getNext(Integer v_Offset, Integer v_pagesize){
           v_Offset += v_pagesize;
           return v_Offset;
       }

       @AuraEnabled(cacheable=true)
       public static Integer getPrevious(Integer v_Offset, Integer v_pagesize){
           v_Offset -= v_pagesize;
           return v_Offset;
       }
    
}


dsiplaycasesTest.apex

@isTest
private class dsiplaycasesTest
{
    @isTest
    static void TestTotalRecords()
    {
        Integer result = dsiplaycases.TotalRecords();
        System.assertEquals(null, result);
    }
 @isTest
    static void TestgetCaseList()
    {
        List<Case> result = dsiplaycases.getCaseList();
        System.assertEquals(null, result);
    }
@isTest
    static void TestgetCaseList2()
    {
        List<Case> result = dsiplaycases.getCaseList(2,3);
        System.assertEquals(null, result);
    }
@isTest
    static void TestgetNext()
    {
        List<Case> result = dsiplaycases.getNext(2,3);// line showing error
        System.assertEquals(null, result);
    }
@isTest
    static void TestgetPrevious()
    {
        List<Case> result = dsiplaycases.getPrevious(2,3);// line showing error
        System.assertEquals(null, result);
    }
}
Abhishek BansalAbhishek Bansal
Hi Devadarsi,

The return type of your method is Integer and you are trying to store the result in a list, that is the reason you are getting the error.
Please find the updated code below:
@isTest
    static void TestgetNext()
    {
        Integer result = dsiplaycases.getNext(2,3);// line showing error
        System.assertEquals(null, result);
    }
@isTest
    static void TestgetPrevious()
    {
        Integer result = dsiplaycases.getPrevious(2,3);// line showing error
        System.assertEquals(null, result);
    }

Let me know if you need any further help on this.

Thanks,
Abhishek Bansal.​​​​​​​