Find your content:

Search form

You are here

Does Site.createPortalUser work in test class?

 
Share

I am writing a test class to test SiteRegisterController.cls. But registerUser is returning null during testing. What could be the problem? Any thoughts?


Attribution to: doga

Possible Suggestion/Solution #1

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites.htm

The test class is clearly documented here.repeating for clarity

 // Test method for verifying the positive test case 

static testMethod void testRegistration() {
    SiteRegisterController controller = new SiteRegisterController();
    controller.username = 'test@force.com';
    controller.email = 'test@force.com';
    controller.communityNickname = 'test';
    // registerUser always returns null when the page isn't accessed as a guest user 

    System.assert(controller.registerUser() == null);
    controller.password = 'abcd1234';
    controller.confirmPassword = 'abcd123';
    System.assert(controller.registerUser() == null);
}

As mentioned we will get null when the page is not accessed as a Guest User.You may use System.Runas(GuestUser) to resolve your issue .


Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4039

My Block Status

My Block Content