+ Start a Discussion
rzsrzs 

Logging to the console in Force.com IDE

Hello,

 

Im using the Force.com IDE for writing Apex code. Is there any way to write debug statements to print a value to the console ?. An example would be really appreciated.

 

Thank You

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

use the system.debug method in your code.

 

for example:

 

system.debug('I have reached this point in the code');

 

 

would print this text when you get to that point in the execution.

The method takes a string, so you can actually include most any data that will display in text format.

I have had a lot of success even putting an object and it will print out the text version of the object (field name and value pairs).

All Answers

JimRaeJimRae

use the system.debug method in your code.

 

for example:

 

system.debug('I have reached this point in the code');

 

 

would print this text when you get to that point in the execution.

The method takes a string, so you can actually include most any data that will display in text format.

I have had a lot of success even putting an object and it will print out the text version of the object (field name and value pairs).

This was selected as the best answer
rzsrzs

Thanks for the reply Jim. I created an Apex trigger in the Force.com IDE , which contains the following code:

 

trigger UpdateAccount on Opportunity (after update) {
      for(Opportunity opp : Trigger.new){
           system.debug('I have reached this point in the code !');    
                       
       }
    }

 

 

Now, i update an Opportunity in my developer organization. But i dont see any log after going to Setup->Monitoring->Debug Logs,even though i have added my account as a user to the Debug Logs.

Also,how to see the log within Force.com IDE itself ?

 

Please help.

Thank You

rzsrzs

Its working now..thanks ! :)

DownstairsBDownstairsB

rzs wrote:

Its working now..thanks ! :)


What did you do?

nateienateie

Would also like to know what you did. Thanks!

Thomas DvornikThomas Dvornik

If you are primarilly doing Apex developement, I would recommend trying the developer console. Just click on you name in the header, and then click "Developer Console." When it is open, logs will be generated without having to set a user in Monitoring. 

 

One tip, if the debug statements aren't showing in the log, check the log levels (Apex should be atleast 'DEBUG').