How to Perform Debugging in Apex

Last updated on Nov 24 2021
Abha Kulkarni

Table of Contents

How to Perform Debugging in Apex

Debugging is a crucial part in any programming development. In Apex, we’ve certain tools which will be used for debugging. one among them is that the system.debug() method which prints the worth and output of variable within the debug logs.
We can use the subsequent two tools for debugging −
• Developer Console
• Debug Logs

Debugging via Developer Console

You can use the Developer console and execute anonymous functionality for debugging the Apex as below −
Example
Consider our existing example of fetching the customer records which are created today. We just want to understand if the query is returning the results or not and if yes, then we’ll check the worth of List.
Paste the code given below in execute anonymous window and follow the steps which we’ve finished opening execute anonymous window.
Step 1 − Open the Developer console
Step 2 − Open the Execute anonymous from ‘Debug’ as shown below.

Salesforce 48
Salesforce

Step 3 − Open the Execute Anonymous window and paste the subsequent code and click on on execute.

Salesforce 49
Salesforce
// Debugging The Apex
List customerList = new List();
customerList = [SELECT Id, Name FROM APEX_Customer__c WHERE CreatedDate =
today];
// Our Query
System.debug('Records on List are '+customerList+' And Records are '+customerList);
// Debug statement to see the worth of List and Size

Step 4 − Open the Logs as shown below.

Salesforce 50
Salesforce

Step 5 − Enter ‘USER’ in filter condition as shown below.
Step 6 − Open the USER DEBUG Statement as shown below.

Debugging via Debug Logs

You can debug an equivalent class via debug logs also . Suppose, you’ve got a trigger in Customer object and it must be debugged for a few variable values, then you’ll do that via the debug logs as shown below −
This is the Trigger Code which updates the outline field if the modified customer is active and you would like to see the values of variables and records currently in scope −

trigger CustomerTrigger on APEX_Customer__c (before update) {
List customerList = new List();
for (APEX_Customer__c objCust: Trigger.new) {
System.debug('objCust current value is'+objCust);

if (objCust.APEX_Active__c == true) {
objCust.APEX_Customer_Description__c = 'updated';
System.debug('The record which has satisfied the condition '+objCust);
}
}
}

Follow the steps given below to get the Debug logs.
Step 1 − Set the Debug logs for your user. attend Setup and sort ‘Debug Log’ in search setup window then click on Link.

Salesforce 51
Salesforce

Step 2 − Set the debug logs as following.

Salesforce 52
Salesforce

 

Salesforce 53
Salesforce

Step 3 − Enter the name of User which needs setup. Enter your name here.

Salesforce 54
Salesforce

Step 4 − Modify the customer records as event should occur to get the debug log.

Salesforce 55
Salesforce

Step 5 − Now attend the debug logs section again. Open the debug logs and click on on Reset.

Salesforce 56
Salesforce

Step 6 − Click on the view link of the primary debug log.

Salesforce 57
Salesforce

Step 7 − look for the string ‘USER’ by using the browser search as shown below.

Salesforce 58
Salesforce

The debug statement will show the worth of the sector at which we’ve set the purpose.
So, this brings us to the end of blog. This Tecklearn ‘How to Perform Debugging in Apex’ blog helps you with commonly asked questions if you are looking out for a job in Salesforce. If you wish to learn Salesforce and build a career in Salesforce domain, then check out our interactive, Salesforce Certification Training: Admin 201 and App Builder, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Salesforce Certification Training: Admin 201 and App Builder

Salesforce Certification Training: Admin 201 and App Builder

About the Course

Salesforce Certification Training course will help you pass the Salesforce Administrator Exam (Admin 201) and the Salesforce App Builder (Dev 401) Exam. Concepts on Force.com Platform, AppExchange, SFDC Security Model, Service Cloud, Sales Cloud, Lightning App Builder, Salesforce Reports & Dashboard can be mastered in this Salesforce Training course. You can also configure the platform, manage users, find better ways to use the platform’s features, build applications with Salesforce Lightning, and more. Further, in this Salesforce certification training course, you will master App builder, Apex, Visualforce, etc.

Why Should you take Salesforce Admin 201 and App Builder Training?

• As per Indeed.com data, 200% global jump in Salesforce jobs since Jan 2016. Salesforce Certified Administrators earn an annual average salary of $87,000 but can go as high as $160,000 depending on their knowledge, skills, and experience.
• More than 200,000 companies worldwide use Salesforce platform. Salesforce leads the CRM market with 19.5 percent of market share – Forbes.
• The global CRM software market will reach US$40.26 billion in 2023, up from US$36.9 billion (2020) – Statista.

What you will Learn in this Course?

Salesforce Fundamentals
• Introduction to CRM concepts and Cloud computing
• Salesforce.com Overview and Fundamentals
• Understanding Salesforce Platform
Understanding Salesforce Platform
• Understanding Salesforce Terminologies and Introducing the force.com platform
• Understanding Salesforce Metadata and API
• Describe the capabilities of the core CRM objects in the Salesforce schema
• Identify common scenarios for extending an org using the AppExchange
• About Salesforce Certification
Introduction to Sales Cloud
• Sales Cloud
• Sales Process
• Sales Productivity Features
• Lead Management
• Lead auto response
• Lead assignment
• Web to lead
• Accounts and Contacts Management
• Opportunities
• Campaign Management
Security Model, User Management and Its Features
• Security Model Mind Map
• System Level or Org Level Security
• User Administration and Troubleshooting
• Permission Sets
• Profile Management
• User Actions
• Assigning Permission
• Session settings
• Activations
• Page layout assignment
• Tab setting
• Field level security
Object, Record and Field Level Features
• Custom Object
• Custom Field
• Data Types
• Relationship among Objects
• Working with App and Tabs
Data Handling and Processing
• Data Import and Export with Salesforce
• Insert, Update and Delete Data with Salesforce
• Export Data with UI
• Export Data using Data Loader Tool
Deployment
• SandBox
• Moving Data from SB to Production – Deployment
• Types of SandBox
• Change Sets
• Types of Change Sets
Application Cycle
• Milestones
• Sandboxes
• Change Sets
• Packages
Reports and Dashboards
Declarative Implementation in Salesforce
Salesforce Development and Apex Programming
• Apex Programming
• Apex Classes
• Apex Settings
• SOQL – Salesforce Object Query Language
• DML Commands
• Apex Class in Detail
• Apex Triggers
• Apex Testing
• Access Specifier in Salesforce
• Testing
Lightning in Salesforce
• Lightning Components
• Lightning Component Capabilities
• Lightning Components vs. Visualforce
Visual Force in Salesforce
• Standard Visualforce controller and controller extensions,
• Visualforce Page
• Understanding the MVC Pattern
• Tools for Visualforce Development
• Visual Force Components
WorkFlows in Salesforce
• Work Flows in Salesforce
• Types of Work Flows
• Work Flows Rules
About Preparation of Salesforce 201 and App Builder Certification exams

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "How to Perform Debugging in Apex"

Leave a Message

Your email address will not be published. Required fields are marked *