Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Use the TestVisible annotation.

private static void yourMethod() {
share|improve this answer
Damn. Never knew that. Very handy. – Caspar Harmer Jul 30 '14 at 7:28

Your Answer


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.