2

I'm getting the error: attempting to reference a null value when trying to test the login method of the Site class. I've tried to see if I can get any error messages. It might be that I'm not creating the community user correct? Here is my test class:

System.runAs(t.adminUser){
    vetAccount = t.createDefaultAccount(randomAccountLastName);
    insert vetAccount;
    communityContact = t.createDefaultContact(randomContactLastName, vetAccount.Id);
    insert communityContact;
    communityUser = t.createDefaultPortalUser(randomEmail, randomContactLastName, randomEmail,randomAlias,communityContact.Id);
    Site.createPortalUser(communityUser,String.valueOf(vetAccount.Id),'1234', false);
}
System.runAs(communityUser){
    CustomLoginController controller = new CustomLoginController();
    t.start();
        controller.username = randomEmail;
        controller.password = '1234';
        PageReference pageRef = controller.login();
        List<ApexPages.Message> apexMessages = ApexPages.getMessages();
    t.stop();
        System.assertEquals('', String.valueOf(pageRef.getContent()));
        /*System.assertEquals(' ', apexMessages[0].getSummary());
        System.assertEquals('', pageRef.getUrl());*/
}

The controller.login is just a wrapper method which returns the page reference from the login method of the Site class.

Looking forward for some answers.

Your Answer

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

Browse other questions tagged or ask your own question.