Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

How can I test private methods in an apex controller ? For instance this example:

 private static string getUserId(String str){
            string UserId = '';
            if(ref != null){
                String[] str = ref.split('bshc=', 2);
                system.debug('***********str***************'+ str[1]);
                String commUserLastdigit = str[1].substring(0,11);
                system.debug('***********communityUserId ***************'+ commUserLastdigit );
                CommUserId = '005c' + commUserLastdigit ;
            }
        return UserId ;
        }
share|improve this question

1 Answer 1

Use the TestVisible annotation.

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_testvisible.htm

@TestVisible 
private static void yourMethod() {
share|improve this answer
    
Damn. Never knew that. Very handy. –  CaspNZ Jul 30 at 7:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.