Skip to content

Instantly share code, notes, and snippets.

@ykurnia
Created May 2, 2024 06:06
Show Gist options
  • Save ykurnia/6e54c3096e93f0e6d306fb1bac5368ef to your computer and use it in GitHub Desktop.
Save ykurnia/6e54c3096e93f0e6d306fb1bac5368ef to your computer and use it in GitHub Desktop.
Salesforce Apex Test Class example for Callout or API call
@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