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
sumit dsumit d 

test class for SocialCaseNotificationController

Hi All,
        how to write the test class for the given class:-
public class SocialCaseNotificationsController {        
    public SocialCaseNotificationsController() {
    }
    
    public List<Case> getlistAccount() {
        Id userId = UserInfo.getUserId();
        return [SELECT Id, CaseNumber, 
                Status 
                FROM Case 
                WHERE (Status = 'Subsq Reopened – Biz Hours' 
                       OR Status = 'Subsq Reopened – Non-Biz Hours')  
                AND OwnerId =: userId 
                ORDER By lastModifiedDate DESC];
    }
    
    public PageReference refresh() {
        getlistAccount();
        return null;
    }
}
Any suggestions?
Yaroslav ProYaroslav Pro
what is your problem? just call the test method in test class and verify result with System.assertEquals();
sumit dsumit d
Hi ,
Parden me.
Actually the Question is this:-https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=9062I000000g3WTQAY
Sampath SuranjiSampath Suranji
Hi,
try something like below,
@istest
public class SocialCaseNotificationsControllerTest {
    
    public static  testmethod void testAcc(){
        try{
            Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
            User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
                              EmailEncodingKey='UTF-8', LastName='TestingUsr', LanguageLocaleKey='en_US', 
                              LocaleSidKey='en_US', ProfileId = p.Id, 
                              TimeZoneSidKey='America/Los_Angeles', UserName='dfstandarduser@testorg.com');
            
            System.runAs(u) {
                
                //insert sample case records
                SocialCaseNotificationsController objCon = new SocialCaseNotificationsController();
                List <case>caseList= objCon.getlistAccount();
                // some assertion
                objCon.refresh();
            }
        }
        catch(Exception ex){}
        
    }
}
refer below for more details,
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
regards
 
sumit dsumit d
Hi sampath,
Actually the Question is  given link this:-https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=9062I000000g3WTQAY
Raj VakatiRaj Vakati
try this
 
@istest
public class SocialCaseNotificationsControllerTest {
    
    public static  testmethod void testAcc(){
        try{
            Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
            User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
                              EmailEncodingKey='UTF-8', LastName='TestingUsr', LanguageLocaleKey='en_US', 
                              LocaleSidKey='en_US', ProfileId = p.Id, 
                              TimeZoneSidKey='America/Los_Angeles', UserName='dfstandarduser@testorg.com');
            
            System.runAs(u) {
			
	

    //create account
    Account acc = new Account();
    //enter details  
    acc.Name = 'Test Account';
    insert acc;
  
    
    
    //create case
    Case c = new Case();
    //enter details
    c.AccountId = acc.Id;
    c.RecordTypeId = 'YOUR_RECORDTYPE_ID';
    c.Type = 'My Type';
    c.Origin = 'My Origin';
    c.Status = 'Subsq Reopened – Biz Hours';
    insert c;
	
	
                
                //insert sample case records
                SocialCaseNotificationsController objCon = new SocialCaseNotificationsController();
                List <case>caseList= objCon.getlistAccount();
                // some assertion
                objCon.refresh();
            }
        }
        catch(Exception ex){}
        
    }
}