Skip to content

Latest commit

 

History

History
91 lines (66 loc) · 2.79 KB

README.md

File metadata and controls

91 lines (66 loc) · 2.79 KB

sf-integration-Base

Lightweight package which aims decrease the development time of new integrations.

Installation

  1. Install npm
  2. Install Salesforce DX CLI
    • Alternative: npm install sfdx-cli --global
  3. Clone this repository (GitHub Desktop is recommended for non-developers)
  4. Run npm install from the project root folder
  5. Install SSDX
    • Non-developers may stop after this step
  6. Install VS Code (recommended)
    • Install Salesforce Extension Pack
    • Install recommended plugins! A notification should appear when opening VS Code. It will prompt you to install recommended plugins.
  7. Install AdoptOpenJDK (only version 8 or 11)
  8. Open VS Code settings and search for salesforcedx-vscode-apex
  9. Under Java Home, add the following:
    • macOS: /Library/Java/JavaVirtualMachines/adoptopenjdk-[VERSION_NUMBER].jdk/Contents/Home
    • Windows: C:\\Program Files\\AdoptOpenJDK\\jdk-[VERSION_NUMBER]-hotspot

Build

To build the project locally follow these steps:

  1. If you have not authenticated to a DevHub run sfdx auth:web:login -d -a production and the log in.
  2. Create scratch org and push project source.
npm install
npm run mac:build

Configuration

The integration can be configured by creating new records on the following Custom Metadata Objects: IntegrationConfiguration__mdt IntegrationService__mdt

Buiding HTTP Clients

Below is a simple example of how to use the CalloutController. Provide the API names of the Custom Metadata records when initializing the request.

Example of using the Callout Controller in a HTTP Cient.

CalloutController callout = new CalloutController();
callout.initRequest('TEST_CONFIG', 'TEST_SERVICE');
callout.sendRequest();

Testing HTTP Clients with CalloutMock

Salesforce does not allow HTTP Callouts in a Test Context. Therefor we need to use Mocks.

In your IntegrationService__mdt it is possible provide a mock response that can be used in a test class.

Example of mock response data structure

{
"200": {
"body": <Add your expected response here>,
"headers": null

},
"500": {
"body": "Internal Server Error",
"headers": null
}

}

Example of testing a HTTP Client

CalloutMock mock = new CalloutMock();
mock.setMock(200, 'OK', 'TEST_SERVICE');

CalloutController callout = new CalloutController();

Test.startTest();
callout.initRequest('TEST_CONFIG', 'TEST_SERVICE');
callout.sendRequest();
Test.stopTest();

Limitations

  • This tool currently only supports REST.