A lightweight, portable, and customizable API mock for Salesforce development. The common use case is mocking a REST API for integration tests, for example, when you cannot wait until the actual API is available. This was originally developed to facilitate efficient integration development on Salesforce platform, but since it is actually an Apex REST web service, it can also be used as a API mock for calls from other systems besides Salesforce.
-
Add
"ZipSupportInApex"
feature to your scratch org definition file and create a scratch org with it. -
Deploy
mock-web-service
folder in this repository. -
Upload API mock responses as zipped csv filed to static resource.
-
Add records to custom metadata
Mock Web Service Setting
to manage the mapping between path and response, and status code. -
https://yourdomain.my.salesforce.com/apexrest/mock/* is the endpoint of the API mock. Get an access token in any way and call the API. If you're developing an integration from Salesforce, see also the following the sample app setup steps.
To make it easier to imagine an actual integration, the following steps shows separately for the integration development org and the API mock org, but they can be the same single org.
-
Deploy
mock-web-service-sample
folder. -
Copy consumer key and consumer secret of the Connected App named
Apex Mock Web Service
. You'll use them later.
-
Deploy
app-sample
folder in this repository. -
Update consumer key and consumer secret field of the Auth. Provider named
Mock API
. -
Copy
Callback URL
. Back to the org for mock web service and update the callback url field of the Connected App with it. -
Update url of the named Named Credential
Mock API
with the org url for mock web service. -
Navigate to the External Credential named
Mock API
. And clickAuthenticate
under action button inExample
principal. -
Login to the org for mock web service and authorize access.
-
Assign permission set
Apex Mock Web Service Sample App
to your user. -
Add
Example Order History
custom lighting component to an account record page and update standardAccount Number
field of an account to0001
,0002
or0003
. You can see the order history based on the api mock response.