1

I have a private method with parameter, How can i debug the below code using Developer Console. Example :

public class TestExam {   
     public static void updateRecord(String name) {

      }
   }

Debug: TestExam.updateRecord('Test');

public class TestExam {   
     private static void updateRecord(String name) {

      }
   }

Debug : ?

Can anyone please guide?

4 Answers 4

2

You could use the @TestVisible annotation to allow test methods to access private or protected members of another class outside the test class.

public class TestExam {   
    @TestVisible Private static void updateRecord(String name) {

    }
}

After adding this annotation you can continue with your current test class and you should now see the parameters of the private method. Take a look at the TestVisible Annotation documents if you want to understand further.

2
  • @TSmith..I know TestVisible Annotation Process . but my question is ,is possible to debug private method in developer console like public method(TestExam.updateRecord('Test');.
    – Sfdcprgmr
    Jan 31, 2017 at 13:41
  • To the best of my knowledge, I am not aware of any accessing to private members through test classes unless you use the @TestVisible annotation. AFAIK Developer console does not give you any extra capabilities for this case.
    – TSmith
    Jan 31, 2017 at 14:02
0

Or for development purpose as well as debug purpose, you can expose private method as public method and on later stage convert it back to public method.

0

In Apex we can't debug private methods, but we can call private method in another method with in the same class.

public class privatemethodclass{
private static string getname(string name){
system.debug(name);
return name;
}
public static void saveacc(){
string nameee = privatemethodclass.getname('Test1234');
system.debug(nameee);
}  
}

enter image description here

0

Developer Console is just a web editor that is developed upon the Salesforce Tooling API and Metadata API, just like Force.com IDE or Mavensmate

Private method in Apex is invisible outside of the containing class interdependently from the editor

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .