• WHO WE ARE
  • WHAT WE DO
    • Salesforce
      • Implementations
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service Lightning
        • Field Service for SMEs
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • Data Science
      • BI Solutions
      • AI/ML solutions
      • Agentic AI
  • HOW WE DO
    • Delivery Model
    • Our Works
  • REACH US
    • Contact Us
    • Careers
  • BLOG
    • WHO WE ARE
    • WHAT WE DO
      • Salesforce
        • Implementations
          • Sales Cloud
          • Service Cloud
          • CPQ
          • Field Service Lightning
          • Field Service for SMEs
        • Developments
          • Salesforce Customization
          • Custom Application Development
          • AppExchange Product Development
        • Migrations
          • Classic to Lightning Migration
          • Other Systems to Salesforce Migration
        • Integrations
      • Data Science
        • BI Solutions
        • AI/ML solutions
        • Agentic AI
    • HOW WE DO
      • Delivery Model
      • Our Works
    • REACH US
      • Contact Us
      • Careers
    • BLOG
  • [email protected]
  • (+91) 44-49521562
Merfantz - Salesforce Solutions for SMEs
Merfantz - Salesforce Solutions for SMEs
  • WHO WE ARE
  • WHAT WE DO
    • Salesforce
      • Implementations
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service Lightning
        • Field Service for SMEs
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • Data Science
      • BI Solutions
      • AI/ML solutions
      • Agentic AI
  • HOW WE DO
    • Delivery Model
    • Our Works
  • REACH US
    • Contact Us
    • Careers
  • BLOG

Part IV. 5. Test Class Creation in Salesforce

  • November 2, 2017
  • Merfantz Editor
  • Salesfore Training Course, SFDC Training Part IV
  • 0

Writing Test Class in Salesforce

The Apex testing framework enables you to write and execute tests for your Apex classes and triggers on the Lightning Platform. Apex unit tests ensure high quality for your Apex code and let you meet requirements for deploying Apex.

Testing is the key to successful long-term development and is a critical component of the development process. The Apex testing framework makes it easy to test your Apex code. Apex code can only be written in a sandbox environment or a Developer org, not in production.

Apex code can be deployed to a production org from a sandbox. Also, app developers can distribute Apex code to customers from their Developer orgs by uploading packages to the Lightning Platform​ AppExchange.

In addition to being critical for quality assurance, Apex unit tests are also requirements for deploying and distributing Apex.

The following are the benefits of Apex unit tests.

  • Ensuring that your Apex classes and triggers work as expected
  • Having a suite of regression tests that can be rerun every time classes and triggers are updated to ensure that future updates you make to your app don’t break existing functionality
  • Meeting the code coverage requirements for deploying Apex to production or distributing Apex to customers via packages
  • High-quality apps delivered to the production org, which makes production users more productive
  • High-quality apps delivered to package subscribers, which increase your customers trust.

Test Method Syntax

Test methods take no arguments and have the following syntax:

@isTest static void testName() {
// code_block
}

Alternatively, a test method can have this syntax:

static testMethod void testName() {
// code_block
}

Using the isTest annotation instead of the testMethod keyword is more flexible as you can specify parameters in the annotation.

Declaring a test method as public or private doesn’t make a difference as the testing framework is always able to access test methods. For this reason, the access modifiers are omitted in the syntax.

Test methods must be defined in test classes, which are classes annotated with isTest.

We have a sample scheduler class and Test class. Please try like the below,

Scheduler Class:

global class ScheduleTerritoryInactiveMemberCheck implements Schedulable { 
    global void execute(SchedulableContext SC) { 
    TerritoryInactiveMemberCheck bcc = new TerritoryInactiveMemberCheck(); 
    bcc.query = 'select id,name from territory'; 
    Database.executeBatch(bcc,200); 
    }
 
} 

Test class:
public static testMethod void testschedule() {
Test.StartTest();
ScheduleTerritoryInactiveMemberCheck sh1 = new ScheduleTerritoryInactiveMemberCheck();
String sch = '0 0 23 * * ?';
system.schedule('Test Territory Check', sch, sh1);
Test.stopTest();
}

We are the ISV Partners and Please reach us for custom development => www.merfantz.com

Please refer the following link to learn more about test class Writing Test class for batch class.

----------------------Hope this will help you!-------------------------





Author Bio

Merfantz Editor
+ Recent Posts
  • August 4, 2023
    How to Setup CRM Analytics for Financial Services Cloud
  • August 2, 2023
    How to Get Started with Salesforce Hyperforce - Merfantz
  • July 28, 2023
    Health Cloud Mastery: Salesforce Trailhead for Effective Healthcare CRM
  • July 26, 2023
    How to integrate Data cloud and Marketing cloud In Salesforce
  • Previous Part IV. 4. Trigger Creation in Salesforce
  • Next Part IV. 6. Components Creation in Salesforce

Leave a Reply

You must be logged in to post a comment.

Merfantz Technologies is a leading Salesforce consulting firm dedicated to helping small and medium enterprises transform their operations and achieve their goals through the use of the Salesforce platform. Contact us today to learn more about our services and how we can help your business thrive.

Discover More

Terms and Conditions
Privacy Policy
Cancellation & Refund Policy

Contact Info

  • No 96, 2nd Floor, Greeta Tech Park, VSI Industrial Estate, Perungudi, Chennai 600 096, Tamil Nadu, INDIA
  • (+91) 44-49521562
  • [email protected]
  • 9:30 IST - 18:30 IST

Latest Posts

Unlocking the Power of Dynamic Forms in Salesforce Lightning App Builder
Unlocking the Power of Dynamic Forms in Salesforce Lightning App Builder May 29, 2025
Einstein Activity Capture Boosting Productivity & Relationship Intelligence
Einstein Activity Capture: Boosting Productivity & Relationship Intelligence May 22, 2025
Let Einstein Help You Build - Salesforce Flow
Let Einstein Help You Build – Salesforce Flow May 15, 2025

Copyright @2023 Merfantz Technologies, All rights reserved