Test class for SObject in Salesforce
Sample Apex Class: public class Sample { public static void insertRecord( SObject objRecord ) { try { insert objRecord; ....
Sample Apex Class: public class Sample { public static void insertRecord( SObject objRecord ) { try { insert objRecord; ....
Sample Apex Class: public class ApprovalProcessController { public static Approval.ProcessResult submitForApproval( Id recordId ) { Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments( 'Submitting request for approval' ); req1.setObjectId( recordId ); Approval.ProcessResult ....
The call to Database.executeBatch should be included within the Test.startTest and Test.stopTest block. The job executes after the call to Test.stopTest. Any asynchronous code included within Test.startTest and Test.stopTest is ....
Sample Code: Apex Class: public class Sample { public Sample() { } public PageReference goToInfallible() { ....
Sample REST Class: @RestResource(urlMapping='/Account/*') global with sharing class SampleRest { @HttpGet global static Account doGet() { RestRequest req = RestContext.request; String acctId = req.requestURI.substring(req.requestURI.lastIndexOf('/') + 1); Account result = [SELECT ....
"Store Only Aggregated Code Coverage" should be disabled to find reliable code coverage.https://help.salesforce.com/s/articleView?id=000332406&type=1. 1. Go to Apex Test Execution. 2. Click "Options". 3. Disable Store Only Aggregated Code Coverage.
Sample Test Class: @isTest private class CollaborationGroupFeedTest { static testMethod void test() { CollaborationGroup cg = new CollaborationGroup(Name = 'Test', CollaborationType = 'Public'); ....
Sample Test Class: @isTest private class CollaborationGroupFeedTest { static testMethod void test() { CollaborationGroup cg = new CollaborationGroup(Name = 'Test', CollaborationType = 'Public'); insert cg; FeedItem FI = new FeedItem(Body ....
Test.getStandardPricebookId() is used to get or fetch the Standard Price Book Id in the Apex test class. Sample Code: Id pricebookId = Test.getStandardPricebookId(); Sample Apex Test Class: @isTest private class ....
Sample Code: public List < SelectOption > exampleProperty { get { //Do something; } } Test Class code: List < SelectOption > ....