+ Start a Discussion
ShikibuShikibu 

how to test as self service user

I have a trigger on CaseComment that wants to run certain code only if the comment was posted by a selfserviceuser.

 

How can I exercise this code in a test class? System.RunAs will not accept a selfserviceuser as argument.

Pradeep_NavatarPradeep_Navatar

In my opinion, create a self service user and specify the username and all other required fields and try using System.runAs().

 

Refer the link http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_selfserviceuser.htm#topic-title for more details.

 

Hope this helps.

ShikibuShikibu

I had already tried this before posting my question:

 

 

        System.runAs([Select Id from SelfServiceUser
                      Where IsActive = True 
                      Limit 1][0]) {
        }

 

Compile Error: runAs requires a single argument of type 'User' or 'Version' at line 9 col 9

 

 

 

        User u = [Select Id from SelfServiceUser
                      Where IsActive = True 
                      Limit 1][0];
        System.runAs(u) {
        }

 

Compile Error: Illegal assignment from SOBJECT:SelfServiceUser to SOBJECT:User at line 10 col 9