+ Start a Discussion

How To print the Log message in console using Apex or Trigger



Can any one help me "How To print the Log message in console using Apex or Trigger"


System.debug('text') wast not working or printing in "System Log"  link, even iadded the user in setup ===> monitoring ===> debug logs.. No Use..


Thnx KarthiVB

It should work. You might have to scroll up to see the result.

Tnx for ur response!


trigger ChangeLeadCheckStatus on Lead (before insert, before update) { system.debug('test Karthig'); if (true) { Lead[] newLead = Trigger.new; for(Lead l :newLead){ l.LastName = l.LastName + '_VB_'; } } 



Can you tell me where 'test Karthig' it will not printing , i have checked in "System Log" link with combination of  Log LogLog category: None Database Workflow Validation Callout Apex Code Apex Profiling Log level:debug, but no text..


2).Also in above trigger code i can't use that one for After trigger ChangeLeadCheckStatus on Lead (after insert, after update).

3).is it possible to update a single field in lead object record using id(if so how to set the id to object). 



Have you been able to figure out why the system log isn't showing any System.Debug messages?


I'm having this issue also. I can see System.Debug messages during unit tests, but they don't show up in the System Log. Even when I have the setting to "Finest".




Jeff, are you saying that the messages don't appear, even when you type System.debug('text') in the System Log window?


Could you supply a copy of the text that appears? (Either scroll up or Select All to grab all the text.)


Ok, I've been struggling with this all day. I have System.Debug peppered throughout my apex controller class, and none of it shows up in the System Log window.


Then I go in and type in System.Debug('Text'); and Execute Apex, and not surprizingly, it works. Then I run my controller and all the Missing debug messages show up. Maybe because I shut it down and restarted everything.


***Begining Page Log for /apex/target20090407204235.927:Class.TargetController.Initialize: line 40, column 17:     returning from end of method public StateData<Constructor>(MAP:String,String) in 1 ms20090407204235.927:Class.SalesOppUtilities.GetFullSalesOpp: line 5, column 46: SOQL query with 1 row finished in 66 ms20090407204235.927:Class.TargetController.Initialize: line 46, column 32:     returning SOBJECT:i360_Sales_Opp__c from method public static SOBJECT:i360_Sales_Opp__c GetFullSalesOpp(Id) in 66 ms20090407204235.927:Class.ProspectUtilities.GetFullProspect: line 284, column 47: SOQL query with 1 row finished in 17 ms20090407204235.927:Class.TargetController.Initialize: line 63, column 29:     returning SOBJECT:i360_Prospect__c from method public static SOBJECT:i360_Prospect__c GetFullProspect(Id) in 18 ms20090407204235.927:Class.TargetController.Initialize: line 81, column 28:     returning String from method public String get(String) in 0 ms20090407204235.927:Class.TargetController.Initialize: line 85, column 13: Interests=Basements;Decks;Garages --- Decoded=Basements;Decks;Garages20090407204235.927:Class.StringUtilities.JoinStr: line 10, column 9: SelectLoop:LIST:String20090407204235.927:Class.TargetController.Initialize: line 88, column 33:     returning String from method public static String JoinStr(LIST:String, String) in 0 ms20090407204235.927:Class.TargetController.Initialize: line 89, column 13: Interests=Basements;Decks;Garages --- parsed=Basements;Decks;Garages20090407204235.927:Class.TargetController.Initialize: line 92, column 20:     returning String from method public String get(String) in 0 ms20090407204235.927:Class.TargetController.Initialize: line 97, column 26:     returning String from method public String get(String) in 0 ms20090407204235.927:Class.TargetController.Initialize: line 100, column 13: 2009-04-0720090407204235.927:Class.TargetController.Initialize: line 103, column 25:     returning String from method public String get(String) in 0 ms20090407204235.927:Class.TargetController.<init>: line 35, column 9:     returning from end of method public void Initialize() in 89 ms


So I have a co-worker that has been having the same problem for a long time. I had him try the same thing, but when he tries to run it from the Execute Apex window, he gets this message:

16:53:30 DEBUG - Executing: system.debug('test'); 16:53:31 ERROR - INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Try logging in again.


And he opened the System Log the same way I did (next to the setup link).


I don't know why mine is now working, but his isn't. It is very difficult to develop and not to be able to see debug messages.


Thanks for your reply,



Message Edited by JPClark on 04-07-2009 05:08 PM
Sorry, theat didn't look that messy when I pasted it in.

When I write code and run Tests, I view the log file that is generated during the test, which appears within Eclipse. So, I don't really use the System Log window except for running occasional Apex commands.


There is also log functionality under Setup/Monitoring/Debug Logs that you can turn on to capture log information.



P.S. If you're inserting code, use the "Insert Code" button to get pretty formatting.