+ Start a Discussion
m 10m 10 

test1 code coverage

Hi Team,
Pleasehelp me below class need to write apex class.
we will appricate baest answer
Apex class:
   global static String setExperienceId(String expId) {    
        // Return null if there is no error, else it will return the error message 
        system.debug('>>>expId>>>'+expId);
        try {
            if (expId != null) {
                Site.setExperienceId(expId);               
            }
            return null; 
        } catch (Exception ex) {
            return ex.getMessage();            
        }        
    } 
 
Agustin BAgustin B
Hi m10, try this approach:
@IsTest
    static void test(){
     string response = setExperienceId(NULL);
     system.assertEquals(NULL,response);
     response = setExperienceId('test');
     system.assertNotEquals(NULL,response);
}

If it helps please like and mark as correct, as it may help others.
VinayVinay (Salesforce Developers) 
Hi,

Try below snippet.
@isTest
private class SetExpecive_test {
    static testMethod void isTest(){        
        test.startTest();
        Apexclassname.setExperienceId('');
        test.stopTest();        
    } 
    static testMethod void isTest1(){
        
        test.startTest();
        Apexclassname.setExperienceId(NULL);
        test.stopTest();
        
    } 
}

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar