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
Alexander RochaAlexander Rocha 

Apex Test Class - Site.login()

Hi everyone,

I'm having a problem here.
I'm trying to test my class, and I can't test "Site.login()" function.

I have a code like this:

logado = Site.login(username, password, null);              
if(logado != null){
    //Some code here
}

No matter which values I pass in the parameters, it always returns null. There's a way to this return true in a apex test class?

Thank you for your attention.
Sorry my bad english.

Alexander Rocha

Tejpal KumawatTejpal Kumawat
Hello Alexander,

Try with this code :
@IsTest global with sharing class SiteLoginControllerTest {
    @IsTest(SeeAllData=true) global static void testSiteLoginController () {
        // Instantiate a new controller with all parameters in the page
        SiteLoginController controller = new SiteLoginController ();
        controller.username = 'test@salesforce.com';
        controller.password = '123456'; 
        controller.login() ;     
    }    
}
If this answers your question then hit Like and mark it as solution!
 
Alexander RochaAlexander Rocha
Hi Tejpal,

That doesn't work.
controller.login() returns a null value.

Thank you for your attention
Alexander Santos Rocha