Created
May 2, 2024 06:06
-
-
Save ykurnia/6e54c3096e93f0e6d306fb1bac5368ef to your computer and use it in GitHub Desktop.
Salesforce Apex Test Class example for Callout or API call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IsTest public class SampleTestClass { | |
@IsTest public static void Test1() | |
{ | |
// upload a file in static resource first | |
StaticResourceCalloutMock mock = new StaticResourceCalloutMock(); | |
mock.setStaticResource('SampleResource'); // name of static resourc | |
mock.setStatusCode(200); | |
mock.setHeader('Content-Type', 'application/json'); // change with correct content type | |
// Set the mock callout mode | |
Test.setMock(HttpCalloutMock.class, mock); | |
// start execute function/method that using callout execution like API call etc | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment