function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AnupamaAnupama 

How to debug Apex classes?

How to debug Apex code?
Best Answer chosen by Admin (Salesforce Developers) 
wesnoltewesnolte

Hey

 

It's not clear is it? :) You can include System.Debug('message') within your code. These debug messages are then available through clicking Setup>Monitoring>Debug logs. Move info is available on that page.

 

Cheers,

Wes 

All Answers

wesnoltewesnolte

Hey

 

It's not clear is it? :) You can include System.Debug('message') within your code. These debug messages are then available through clicking Setup>Monitoring>Debug logs. Move info is available on that page.

 

Cheers,

Wes 

This was selected as the best answer
aalbertaalbert

The first key is to ensure you have system.debug messages in your code. Then to output those debug messages, you can use the Debug Logs (mentioned in the previous post), or System Log in the browser. You also can look at the debug output when executing your test methods.

 

AnupamaAnupama
Thanks wesnolte and aalbert for the answers.
MukulMukul

Hi wesnolte,

 

I cant seem to see my System.debug statements on Monitoring->Debug Log. 

 

I am trying to print a dynamic query and its just not printing in there. On clicking the button, Apply Scoring Rule, i dont see any System.debug statements in the log. If you need more detail, i can post my code here.

 

public void executeLead() { System.debug('************ Query: ************ '); if(lead == null) lead = new Lead(); // Get Leads based on the selected Value String leadQry = 'select FirstName, LastName, NumberOfEmployees,' + 'AnnualRevenue from lead where ' + fldDate + ' >= ' + StartDate + ' and ' + fldDate + ' <= ' + EndDate; System.debug('************ Query: ************ ' + leadQry); leads = Database.Query(leadQry); // return leads; // return null; } public List<Lead> getLead() { return leads; }

public PageReference ApplyScoringRule() {
// Now set the method depending on what it is;
// String cMappingRule = getQuery();
// String cQuery = getLead();
System.debug('******HERE*****');
List<Lead> results = getLead();
// If zero or more than 250 records returned, display a message
if (results.size() == 250) ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'NOTE: Only the first 250 rows are displayed.'));
if (results.size() == 0) ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'NO RECORDS FOUND.'));

// searchResults.add(new showLeads(ld));
for (Lead c : results) {
// System.Debug();
searchResults.add( new showLeads(c) ) ;
}

return null;
// return cQuery;
}
 

 

 

 

 

wesnoltewesnolte

Hey

 

Do you see anything on that page? The info on the page should be able to help you, but just in case I'd like to ask if 

 

1. You are clicking the 'new' button on that page and adding your user to the debug logs

2. After doing this do you go to your page and click the button?

3. You then have to return to the debug page and refresh it. The most recent entry is probably the relevant one.

 

Wes

jdance1.3948195933250098E12jdance1.3948195933250098E12
Not having the ability to do true debugging is insane. Just saying. 
jdance1.3948195933250098E12jdance1.3948195933250098E12
FYI - It is now - Setup>Logs>Debug logs
Nazrul AminNazrul Amin
Thanks System.Debug('message') was all I needed to know from here.  Also you can find the Logs in Developer Console "Logs" tab.