How to write test class for HTTPCallouts in Salesforce?
Sample HTTPCallout Class: public class AnimalLocator { public static String getAnimalNameById(Integer id) { Http http = new Http(); HttpRequest request ....
Sample HTTPCallout Class: public class AnimalLocator { public static String getAnimalNameById(Integer id) { Http http = new Http(); HttpRequest request ....
The mock HTTPCallOuts available in Salesforce are below 1. StaticResourceCalloutMock2. HttpCalloutMock Test class for HTTPCallouts in Salesforce Sample HTTPCallout Class: public class AnimalLocator { public static String getAnimalNameById( Integer id ....
To cover the test coverage for getURL method, use Test.setCurrentPage(Page.PageName). Test.setCurrentPage(Page.PageName) will help you to cover the codes which makes use of ApexPages.currentPage().getUrl(). Cheers!!!
Test.startTest() and Test.stopTest() are very useful when your test class hits Salesforce Governor Limits. These methods can be used to reset the governor limits within a test class. Check the below ....
Sample Code: Employee__c emp = new Employee__c(Employee_Name__c = 'Testsing'); insert emp; Test.setCreatedDate(emp.Id, DateTime.newInstance(2000,10,10)); Check the below link for more information https://developer.salesforce.com/docs/atlas.en-us.200.0.apexcode.meta/apexcode/apex_methods_system_test.htm#apex_System_Test_setCreatedDate ....
Sample Apex Class: public class Sample { public Sample() { } public PageReference goToInfallible() { PageReference pg = ....
Sample Class: public class LeadCreation { public Lead objLead; public String lastName; public LeadCreation() { } ....
Sample Class: public class LeadCreation { public Lead objLead; public String lastName; public LeadCreation() { } public PageReference newLead() { objLead = new Lead(Company = 'Test', LastName = lastName, Status ....
Sample Trigger: trigger RestrictContactByName on Contact (before insert, before update) { for (Contact c : Trigger.New) { if(c.LastName == 'INVALIDNAME') { ....
To Set Up Test Data for an Entire Test Class in Salesforce, @testSetup is used. Sample Test Class: @isTest private class CommonTestSetup { /* Method to setup data */ ....