Salesforce REST API lets you integrate Salesforce into the External system. With REST API

we can expose our salesforce org data to an external system or we can fetch data from an external system into the Salesforce org.

Now if we have created any API in our system then we have to test it if it is working fine for users. Several methods exist for testing APIs, but Swagger is a popular one.

Swagger is one of the tools for documenting API. You can test your API right in the documentation using Swagger. JSON or YAML can be used to define Swagger definitions.

So here in this blog, we tried to let you know how to configure your org so that you can test your APIs using swagger. Let’s begin

Complete guide to test APIs using Swagger

Here we are using a “httpget” request to make you familiar with how we can use the swagger API tool for exposing salesforce org data to an external system.

In this scenario, we hit a get request in the swagger editor and it will give us the order list in the form of JSON.

Here are the steps:

Step 1. First, make your apex class available for the Rest web services by using a global specifier for both class and method.

Code of APEX class

Step 2. Now in Setup go to the quick find box and type sites

Step 3. If you are not having any sites please create one and if you are having sites please select any site. Here we will permit the external user to access our class.

Step 4. After selecting the sites click on “Public Access Settings”.

   Step 5. Here click on “Enabled Apex Class Access”

Step 6. Here we are going to add the apex class so click on edit.

Step 7. Select the apex class which you have created as an API and add it

Step 8. Now after adding the class to the site user we still have to add the swagger site to CORS so that the swagger website is able to access our org. So go to the quick find box and type CORS

Step 9. Click on the New button

Step 10. Add this Url to CORS

Step 11.Create a Swagger file

Here we are done with our setting now we have to create a Swagger file for this go to this link and create a new file.

(i) Here first we have swagger as a starting element and its version must be not more than 2.0.
(ii) now in info define any version and title of your choice.
(iii) In the host tag define your org URL while in the path tag defines your base path and add /service/apexrest as it is necessary to hit APEX APIs.
(iv) after that in path define the URL/path that you have mentioned in your class. And start coding

As per the need of your class.

Swagger Code:

Step 12. Once your swagger code is complete, on the right side you will get the UI to work on.

Here just for testing purposes paste our code and you will get a list of orders from our org. Click on GET Button and you will get the result.

Step 13. Click on Execute Button and it will hit the API whose URL is provided in the swagger method.

Step 14. Here you will get the response depending on the response body you have sent by your apex class.

Conclusion

So, here it is, a complete guide on using Swagger to test APIs in salesforce.

We’d love to hear about your experience with the solution. Keep an eye out for more interesting Salesforce development solutions on our blogs and Stay tuned for the next one. Happy Learning!

Share This Blog
Related Articles

Salesforce CPQ (Configure, Price, Quote) is a powerful tool that enables businesses to streamline their quoting process by providing advanced configuration options. Among its many features, Multi-Dimensional Quoting (MDQ) stands out as a powerful capability that allows sales teams to create more detailed and flexible quotes for complex products. In this blog, we’ll dive into […]

Read More
Dynamic Search Filters in Salesforce CPQ

Salesforce CPQ (Configure, Price, Quote) is a powerful tool that allows sales teams to generate quotes with speed and accuracy. One of the key features that makes CPQ so flexible is its dynamic search filter capability. In this blog, we’ll explore how you can create dynamic search filters in Salesforce CPQ to make your quoting […]

Read More
How to Create Quote Templates Customization Methods

The objective after completing a quote is usually to produce a precise and expert quote document for clients. However, without the proper procedures in place, quoting can be difficult, error-prone, and time-consuming. Salesforce CPQ (Configure, Price, Quote) streamlines the process and improves quote accuracy by assisting with the setup and administration of quotation papers. By […]

Read More
Boost Performance with a Robust Trigger Framework in Salesforce

Boost Performance with a Robust Trigger Framework in Salesforce If you want to make sure of scalability and performance in the Salesforce development, managing Apex triggers is a must. With a trigger framework, you get a structured approach to organizing and maintaining trigger logic. This way, developers can follow the best practices while maintaining the […]

Read More

When it comes to Salesforce development, efficiently managing and deploying metadata is important to maintain streamlined operations. With the help of Unlocked Package, you can easily achieve this. It is specially designed for business’s internal use and allows businesses to develop and manage modular applications. This blog will walk you through the importance of Unlocked […]

Read More
How Salesforce Data Cloud Streamlines Data Management

The Data Cloud integrates your company’s data onto Salesforce’s Einstein 1 Platform. It provides each team with a comprehensive customer view for a better experience. The Data Cloud consolidates disparate data sources into a unified model, facilitating easy access and comprehension. It encompasses various data types such as web engagement and more from both internal […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
43 Lafferty Lane, Richmond Hill, L4C 3N8, CA +1(262) 310-7818