{"id":710,"date":"2016-08-09T06:38:19","date_gmt":"2016-08-09T06:38:19","guid":{"rendered":"https:\/\/eshopsync.com\/?p=710"},"modified":"2025-10-14T10:07:07","modified_gmt":"2025-10-14T10:07:07","slug":"test-classes-apex-salesforce","status":"publish","type":"post","link":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/","title":{"rendered":"Test Classes In Apex Salesforce"},"content":{"rendered":"<p>Before Knowing how to write\u00a0<strong>Test Classes In Apex Salesforce\u00a0<\/strong>we should why we\u00a0write\u00a0<strong>Test Classes.<\/strong><\/p>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\">Need Of Writing Test Classes<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p>We write Test Classes In Apex Salesforce for Unit Testing. We get to find the bugs in our code and fix it to give better output. Testing gives the <strong>Code Coverage<\/strong>, first of all we should know What Code Coverage is? It is the line of code which are covered through testing.The code must have 75% code coverage in order to be deployed to Production. It is discussed further below.<\/p>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\">Data Access<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p><strong>@isTest annotation:<\/strong><br \/>\nThe test class are written under <strong>@isTest<\/strong> annotation. By using this annotation for test class we maintain code limit as it is not counted in it.<\/p>\n<p><strong>Create Raw-Data At First:<\/strong><br \/>\nThe <strong>Test Class In Apex Salesforce<\/strong> does not have access to any of the data which is stored in the related Salesforce org by default.We need to create raw-data for test class in our test class itself. By adding <strong>SeeAllData=true<\/strong> to @isTest annotation i.e. <strong>@isTest(SeeAllData=true)<\/strong> grants the access to the all the data of the related Salesforce org.<\/p>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\">Code<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p><strong>Test Class for trigger:<\/strong><br \/>\nHere is the Trigger for which we will be writing test class:<\/p>\n<pre class=\"brush:java\">trigger bookTrigger on book__c (before insert) {\r\n        \r\n        \/**\r\n         * Webkul Software.\r\n         *\r\n         * @category  Webkul\r\n         * @author    Webkul\r\n         * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\r\n         * @license   https:\/\/store.webkul.com\/license.html\r\n         *\/\r\n        \r\n        list&lt;book__c&gt; li = trigger.new;\r\n        \r\n        for(book__c str : li){\r\n            str.Price__c = str.Price__c * 0.8;\r\n        } \r\n        \r\n}\r\n<\/pre>\n<p>Now the test class will be as follows:<\/p>\n<pre class=\"brush:java\">@isTest\r\nprivate class bookTriggerTest {\r\n\r\n    \/**\r\n     * Webkul Software.\r\n     *\r\n     * @category  Webkul\r\n     * @author    Webkul\r\n     * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\r\n     * @license   https:\/\/store.webkul.com\/license.html\r\n     *\/\r\n\r\n    static testMethod void validateHelloWorld() {\r\n       Book__c b = new Book__c(Name='Behind the Cloud', Price__c=100);\r\n       System.debug('Price before inserting new book: ' + b.Price__c);\r\n\r\n      \/\/ Insert book\r\n       insert b;\r\n\r\n       \/\/ Retrieve the new book\r\n       b = [SELECT Price__c FROM Book__c WHERE Id =:b.Id];\r\n       System.debug('Price after trigger fired: ' + b.Price__c);\r\n\r\n       \/\/ Test that the trigger correctly updated the price\r\n       System.assertEquals(80, b.Price__c);\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Test Class For Extension:<\/strong><br \/>\nHere is the Controller Extension for which we will be writing test class:<\/p>\n<pre class=\"brush:java\">public with sharing class contactext {\r\n    \r\n   \/**\r\n    * Webkul Software.\r\n    *\r\n    * @category  Webkul\r\n    * @author    Webkul\r\n    * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\r\n    * @license   https:\/\/store.webkul.com\/license.html\r\n    *\/\r\n\r\n    public contact con;\r\n    \r\n    public contactext(ApexPages.StandardController std){\r\n        \r\n            con = (contact)std.getrecord();\r\n            \r\n    }\r\n    \r\n    public pagereference savedata(){\r\n    \r\n        try{\r\n        \r\n            insert con;\r\n            apexpages.addmessage(new apexpages.Message(apexpages.severity.confirm,'Contact Saved'));\r\n        \r\n        }catch(exception e){\r\n        \r\n            apexpages.addMessages(e);\r\n        \r\n        }\r\n        \r\n        pagereference pg = page.Task02_Contactext;\r\n        pg.setredirect(true);\r\n    \r\n        return pg;\r\n    \r\n    }    \r\n    \r\n}<\/pre>\n<p>Now the test class will be as follows:<\/p>\n<pre class=\"brush:java\">@isTest\r\npublic class contactextTest\r\n{\r\n\r\n   \/**\r\n    * Webkul Software.\r\n    *\r\n    * @category  Webkul\r\n    * @author    Webkul\r\n    * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\r\n    * @license   https:\/\/store.webkul.com\/license.html\r\n    *\/\r\n\r\n   @isTest static void testMethodForException()\/\/Checking Records for exception\r\n    {\r\n\tAccount testAccount = new Account();\/\/Insert Account\r\n        testAccount.Name='Test Account' ;\r\n        insert testAccount;\r\n        Contact cont = new Contact();\r\n        cont.FirstName ='Test';\r\n        cont.LastName ='Test';\r\n        cont.accountid =testAccount.id;\r\n        insert cont;\r\n        ApexPages.StandardController sc = new ApexPages.StandardController(cont);\r\n        contactext contactextObj = new contactext(sc);\/\/Instantiate the Class\r\n        try\r\n        {\r\n            contactextObj.savedata();\/\/Call the Method\r\n        }\r\n        catch(Exception e)\r\n        {}\r\n        list&lt;account&gt; acc = [select id from account];\/\/Retrive the record\r\n        integer i = acc.size();\r\n        system.assertEquals(1,i);\/\/Test that the record is inserted        \r\n        \r\n    }\r\n\t@isTest static void testMethod1()\/\/Testing the insertion method\r\n    {\r\n        Account testAccount = new Account();\/\/Insert Account\r\n        testAccount.Name='Test Account' ;\r\n        insert testAccount;\r\n        Contact cont = new Contact();\r\n        cont.FirstName ='Test';\r\n        cont.LastName ='Test';\r\n       cont.accountid =testAccount.id;\r\n\t  \r\n            try\r\n            {\r\n                ApexPages.StandardController sc = new ApexPages.StandardController(cont);\r\n                contactext contactextObj = new contactext(sc);\/\/Instantiate the Class\r\n                contactextObj.savedata();\r\n\t         }\r\n            catch(Exception ee)\r\n            {}\r\n            list&lt;account&gt; acc = [select id from account];\/\/Retrive the record\r\n\t        integer i = acc.size();\r\n\t        system.assertEquals(1,i);\/\/Test that the record is inserted\r\n        \r\n    }     \r\n}<\/pre>\n<p><strong>Test Class For Controller:<\/strong><br \/>\nHere is the class for which we will be writing test class:<\/p>\n<pre class=\"brush:java\">public with sharing class retrieveAcc {\r\n    \r\n    \/**\r\n     * Webkul Software.\r\n     *\r\n     * @category  Webkul\r\n     * @author    Webkul\r\n     * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\r\n     * @license   https:\/\/store.webkul.com\/license.html\r\n     *\/\r\n\r\n    public list&lt;account&gt; getacc(){\r\n    \t\r\n    \tlist&lt;account&gt; li = [select Name,AccountNumber,AccountSource,ParentId from account];\r\n    \t\r\n    \tif(li!=null &amp;&amp; !li.isEmpty()){\r\n    \t\r\n    \t\treturn li;\r\n    \t\r\n    \t}else{\r\n    \t\r\n    \t\treturn new list&lt;account&gt;();\r\n    \t\r\n    \t}    \r\n    \t\r\n    }\r\n    \r\n}<\/pre>\n<p>Now the test class will be as follows:<\/p>\n<pre class=\"brush:java\">@isTest\r\nprivate class retriveAccTest {\r\n\r\n        \/**\r\n         * Webkul Software.\r\n         *\r\n         * @category  Webkul\r\n         * @author    Webkul\r\n         * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\r\n         * @license   https:\/\/store.webkul.com\/license.html\r\n         *\/\r\n\r\n\t@isTest static void testmeth1(){\r\n\t\t\/\/Insert Record for testing the If situation\r\n\t\taccount acc1 = new account(name = 'acc1', AccountSource = 'Web');\r\n\t\taccount acc2 = new account(name = 'acc2', AccountSource = 'Web');\r\n\t\tlist&lt;account&gt; accList = new list&lt;account&gt;();\r\n\t\taccList.add(acc1);\r\n\t\taccList.add(acc2);\r\n\t\tinsert accList;\r\n\t\t\r\n\t\t\/\/Test that Records are Inserted\r\n\t\tlist&lt;account&gt; obj1 = new retrieveAcc().getacc();\r\n\t\tsystem.assertequals(obj1.size(),2);\r\n\t\t\r\n\t\t\/\/Delete Records For testing the Else situation\r\n\t\tdelete accList;\r\n\t\t\r\n\t\t\/\/Test that Records are Deleted\r\n\t\tlist&lt;account&gt; obj2 = new retrieveAcc().getacc();\r\n\t\tsystem.assertEquals(obj2.size(),0); \r\n\t}     \r\n}<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\">How to Run A Test Class In Developer Console<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p><strong>Step-1:<\/strong><br \/>\nOpen the Developer Console Window.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-715 size-full\" src=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step1.png\" alt=\"Step1\" width=\"1277\" height=\"213\" srcset=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step1.png 1277w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step1-300x50.png 300w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step1-768x128.png 768w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step1-1024x171.png 1024w\" sizes=\"auto, (max-width: 1277px) 100vw, 1277px\" \/><\/p>\n<p><strong>Step-2:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-716 size-full\" src=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step2.png\" alt=\"Step2\" width=\"1039\" height=\"639\" srcset=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step2.png 1039w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step2-300x185.png 300w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step2-768x472.png 768w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step2-1024x630.png 1024w\" sizes=\"auto, (max-width: 1039px) 100vw, 1039px\" \/><\/strong><\/p>\n<p><strong>Step-3:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-717 size-full\" src=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step3.png\" alt=\"Step3\" width=\"1032\" height=\"637\" srcset=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step3.png 1032w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step3-300x185.png 300w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step3-768x474.png 768w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Step3-1024x632.png 1024w\" sizes=\"auto, (max-width: 1032px) 100vw, 1032px\" \/><\/strong><\/p>\n<p><strong>Step-4:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-714 size-full\" src=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Last.png\" alt=\"Last\" width=\"1129\" height=\"393\" srcset=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Last.png 1129w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Last-300x104.png 300w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Last-768x267.png 768w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/Last-1024x356.png 1024w\" sizes=\"auto, (max-width: 1129px) 100vw, 1129px\" \/><\/strong><\/p>\n<p><strong>Code Coverage:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-712 size-full\" src=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage.png\" alt=\"CodeCoverage\" width=\"1004\" height=\"438\" srcset=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage.png 1004w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage-300x131.png 300w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage-768x335.png 768w\" sizes=\"auto, (max-width: 1004px) 100vw, 1004px\" \/><\/strong><\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-713 size-full\" src=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage2.png\" alt=\"CodeCoverage2\" width=\"1131\" height=\"638\" srcset=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage2.png 1131w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage2-300x169.png 300w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage2-768x433.png 768w, https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/08\/CodeCoverage2-1024x578.png 1024w\" sizes=\"auto, (max-width: 1131px) 100vw, 1131px\" \/><\/strong><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\"><i class=\"fa fa-user\"><\/i>Support<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p>That\u2019s all for Implementing Test Classes In Apex Salesforce, still have any issue feel free to add a ticket and let us know your views to make the code better <strong><a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\" rel=\"nofollow\"> https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/<\/a><\/strong><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p class=\"entry-title\"><strong>Read More:<a href=\"https:\/\/eshopsync.com\/schedule-job-how-to-delete-it-using-apex-in-salesforce\/\">How to Delete it using Apex in Salesforce?<\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before Knowing how to write\u00a0Test Classes In Apex Salesforce\u00a0we should why we\u00a0write\u00a0Test Classes. Need Of Writing Test Classes We write Test Classes In Apex Salesforce for Unit Testing. We get<a href=\"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/\"> &#8230;<\/a><\/p>\n","protected":false},"author":6,"featured_media":672,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[75,76,77],"class_list":["post-710","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","tag-test-classes","tag-test-classes-apex","tag-test-classes-salesforce"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to write Test Classes in Apex Salesforce<\/title>\n<meta name=\"description\" content=\"This blog explains about writing the Test Classes in Apex Salesforce. It Explains about What are the Do&#039;s and Don&#039;ts for writing the Test Classes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to write Test Classes in Apex Salesforce\" \/>\n<meta property=\"og:description\" content=\"This blog explains about writing the Test Classes in Apex Salesforce. It Explains about What are the Do&#039;s and Don&#039;ts for writing the Test Classes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/\" \/>\n<meta property=\"og:site_name\" content=\"eShopSync\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-09T06:38:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-14T10:07:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/06\/Code-Snippet-eshopsync-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"945\" \/>\n\t<meta property=\"og:image:height\" content=\"356\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Aakanksha Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aakanksha Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/\"},\"author\":{\"name\":\"Aakanksha Singh\",\"@id\":\"https:\\\/\\\/eshopsync.com\\\/#\\\/schema\\\/person\\\/0c0abdfe9996c433a577308c6e67cd39\"},\"headline\":\"Test Classes In Apex Salesforce\",\"datePublished\":\"2016-08-09T06:38:19+00:00\",\"dateModified\":\"2025-10-14T10:07:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/\"},\"wordCount\":341,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/eshopsync.com\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/Code-Snippet-eshopsync-2.png\",\"keywords\":[\"Test Classes\",\"Test Classes Apex\",\"Test Classes Salesforce\"],\"articleSection\":[\"Salesforce\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/\",\"url\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/\",\"name\":\"How to write Test Classes in Apex Salesforce\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/eshopsync.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/eshopsync.com\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/Code-Snippet-eshopsync-2.png\",\"datePublished\":\"2016-08-09T06:38:19+00:00\",\"dateModified\":\"2025-10-14T10:07:07+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/eshopsync.com\\\/#\\\/schema\\\/person\\\/0c0abdfe9996c433a577308c6e67cd39\"},\"description\":\"This blog explains about writing the Test Classes in Apex Salesforce. It Explains about What are the Do's and Don'ts for writing the Test Classes.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/#primaryimage\",\"url\":\"https:\\\/\\\/eshopsync.com\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/Code-Snippet-eshopsync-2.png\",\"contentUrl\":\"https:\\\/\\\/eshopsync.com\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/Code-Snippet-eshopsync-2.png\",\"width\":945,\"height\":356},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/eshopsync.com\\\/test-classes-apex-salesforce\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/eshopsync.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Test Classes In Apex Salesforce\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/eshopsync.com\\\/#website\",\"url\":\"https:\\\/\\\/eshopsync.com\\\/\",\"name\":\"eShopSync\",\"description\":\"Salesforce, SAP, Pardot Integration For E-Commerce Store\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/eshopsync.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/eshopsync.com\\\/#\\\/schema\\\/person\\\/0c0abdfe9996c433a577308c6e67cd39\",\"name\":\"Aakanksha Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/eef6d7ed23fc4ad8f12c94d6d6d30ec2ebbb9bedbf9d8a9dc8626a3a171fa3fa?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/eef6d7ed23fc4ad8f12c94d6d6d30ec2ebbb9bedbf9d8a9dc8626a3a171fa3fa?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/eef6d7ed23fc4ad8f12c94d6d6d30ec2ebbb9bedbf9d8a9dc8626a3a171fa3fa?s=96&d=mm&r=g\",\"caption\":\"Aakanksha Singh\"},\"url\":\"https:\\\/\\\/eshopsync.com\\\/author\\\/aakanksha-singh391\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to write Test Classes in Apex Salesforce","description":"This blog explains about writing the Test Classes in Apex Salesforce. It Explains about What are the Do's and Don'ts for writing the Test Classes.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/","og_locale":"en_US","og_type":"article","og_title":"How to write Test Classes in Apex Salesforce","og_description":"This blog explains about writing the Test Classes in Apex Salesforce. It Explains about What are the Do's and Don'ts for writing the Test Classes.","og_url":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/","og_site_name":"eShopSync","article_published_time":"2016-08-09T06:38:19+00:00","article_modified_time":"2025-10-14T10:07:07+00:00","og_image":[{"width":945,"height":356,"url":"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/06\/Code-Snippet-eshopsync-2.png","type":"image\/png"}],"author":"Aakanksha Singh","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Aakanksha Singh","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/#article","isPartOf":{"@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/"},"author":{"name":"Aakanksha Singh","@id":"https:\/\/eshopsync.com\/#\/schema\/person\/0c0abdfe9996c433a577308c6e67cd39"},"headline":"Test Classes In Apex Salesforce","datePublished":"2016-08-09T06:38:19+00:00","dateModified":"2025-10-14T10:07:07+00:00","mainEntityOfPage":{"@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/"},"wordCount":341,"commentCount":0,"image":{"@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/#primaryimage"},"thumbnailUrl":"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/06\/Code-Snippet-eshopsync-2.png","keywords":["Test Classes","Test Classes Apex","Test Classes Salesforce"],"articleSection":["Salesforce"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/eshopsync.com\/test-classes-apex-salesforce\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/","url":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/","name":"How to write Test Classes in Apex Salesforce","isPartOf":{"@id":"https:\/\/eshopsync.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/#primaryimage"},"image":{"@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/#primaryimage"},"thumbnailUrl":"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/06\/Code-Snippet-eshopsync-2.png","datePublished":"2016-08-09T06:38:19+00:00","dateModified":"2025-10-14T10:07:07+00:00","author":{"@id":"https:\/\/eshopsync.com\/#\/schema\/person\/0c0abdfe9996c433a577308c6e67cd39"},"description":"This blog explains about writing the Test Classes in Apex Salesforce. It Explains about What are the Do's and Don'ts for writing the Test Classes.","breadcrumb":{"@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eshopsync.com\/test-classes-apex-salesforce\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/#primaryimage","url":"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/06\/Code-Snippet-eshopsync-2.png","contentUrl":"https:\/\/eshopsync.com\/wp-content\/uploads\/2016\/06\/Code-Snippet-eshopsync-2.png","width":945,"height":356},{"@type":"BreadcrumbList","@id":"https:\/\/eshopsync.com\/test-classes-apex-salesforce\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eshopsync.com\/"},{"@type":"ListItem","position":2,"name":"Test Classes In Apex Salesforce"}]},{"@type":"WebSite","@id":"https:\/\/eshopsync.com\/#website","url":"https:\/\/eshopsync.com\/","name":"eShopSync","description":"Salesforce, SAP, Pardot Integration For E-Commerce Store","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eshopsync.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/eshopsync.com\/#\/schema\/person\/0c0abdfe9996c433a577308c6e67cd39","name":"Aakanksha Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/eef6d7ed23fc4ad8f12c94d6d6d30ec2ebbb9bedbf9d8a9dc8626a3a171fa3fa?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/eef6d7ed23fc4ad8f12c94d6d6d30ec2ebbb9bedbf9d8a9dc8626a3a171fa3fa?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eef6d7ed23fc4ad8f12c94d6d6d30ec2ebbb9bedbf9d8a9dc8626a3a171fa3fa?s=96&d=mm&r=g","caption":"Aakanksha Singh"},"url":"https:\/\/eshopsync.com\/author\/aakanksha-singh391\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/posts\/710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":5,"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"predecessor-version":[{"id":13630,"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/posts\/710\/revisions\/13630"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/media\/672"}],"wp:attachment":[{"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eshopsync.com\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}