Trailhead is the innovative, interactive, guided learning experience for Salesforce developers, admins, and users and it has just gotten even more useful and awesome with the release of more content. It is often the case that orgs need the ability to integrate with external systems and the solution requires Apex integration code to be written. As Salesforce developers it is up to us to be familiar with and know the capabilities of the Apex APIs available to us so that we can make the right choice for the situation. There is a new Trailhead module Apex Integration Services that covers SOAP and REST callouts for outgoing integrations and Apex Web Services for handing incoming integrations. This post details my experience and takeaways from completing it.
Apex Integration Overview
The Apex Integration Overview unit gives a quick overview of callouts and steps you through setting up Remote Sites that will be used in the rest of the module. The unit goes a bit into REST vs. SOAP use cases, but a deep dive into that is not its main purpose, hence the word “overview” in the unit title. However, one of the nuggets to not overlook is the resource link at the end to an article REST vs SOAP: When is REST better? which goes deeper. After you finish this module you should have an understanding of when to use REST vs. SOAP and understand how to set up Remote Sites.
Apex REST Callouts
The Apex REST Callouts unit gives a very good, concise and useful explanation of HTTP communications. HTTP methods are explained and the main HTTP methods (e.g., GET, POST, etc.) are detailed. Additionally, HTTP status codes are explained and the main status codes (200,404, etc.) are touched on. Links to the complete Salesforce documentation on them are given as well. The unit walks you through creating a GET and a POST callout and then has you write unit tests for them. The very useful JSON2Apex app for generating Apex classes from JSON for strongly typed deserialization is mentioned. Unit tests are explained, with mocks taking center stage. I liked that the static resource mocking method was shown. The other cool thing about this unit is that it has you use the Developer Console to run the tests. In case you haven’t noticed, the Developer Console now lets you run single test methods at a time and lets you easily rerun tests and rerun only failed tests. I’ve been using the Developer Console for test running for this feature and loving it!
Apex SOAP Callouts
The Apex SOAP Callouts unit gives a good look into the mechanisms needed to implement SOAP callouts. The WSDL2Apex tool for creating classes from WSDL files is explained and is part of the challenge, so you end up getting hands on with it. Like explained in the REST unit, mocks are used to unit test the SOAP services as well. Don’t skip over the resources at the end or you’ll miss the link to the blog article that announced the open source WSDL2Apex generator.
Apex Web Services
The Apex Web Services unit touches briefly on Apex SOAP and then goes in depth on how to develop Apex REST classes. The way to properly annotate and handle the different HTTP methods is explained. There is a good tip about how to version your API endpoints using the urlMapping of the @RestResource annotation. The RestContext class and its contained classes are explained and how to unit test an Apex REST class is demonstrated. If you find the need to parse out portions of Strings in your class check out the docs on the String class as there are a ton of methods for doing so. As you develop the services, you’ll find yourself wanting to have a way to easily test them. This unit did a great job of going into detail of how to access your REST endpoints with Workbench and with cURL.
The unit is an excellent resource for developers that need to get up to speed on Apex integration methods quickly and effectively. The module will give you the knowledge you need to be able to determine which type of service to use (SOAP or REST) and the different Apex APIs available. I highly recommend you head on over to Trailhead and complete the Apex Integration Services module to improve your skills and make yourself more valuable. Happy Trails!