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:

    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);
    CustomLoginController controller = new CustomLoginController();
        controller.username = randomEmail;
        controller.password = '1234';
        PageReference pageRef = controller.login();
        List<ApexPages.Message> apexMessages = ApexPages.getMessages();
        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.