Welcome to the first lesson of the Integration Developer program! In this lesson, you'll learn the fundamentals of making HTTP callouts in Salesforce using a free, public API called JSONPlaceholder.
By the end of this lesson, you will be able to:
- Understand and implement all major HTTP methods (GET, POST, PUT, PATCH, DELETE)
- Make HTTP callouts from Salesforce Apex
- Work with JSON request and response bodies
- Write proper test classes for HTTP callouts
- Use mock responses in your tests
This exercise contains three main components:
-
JSONPlaceholderExercise.cls
- Contains skeleton methods for each HTTP operation
- Includes detailed TODO comments to guide your implementation
- Located in
force-app/main/default/classes/
-
JSONPlaceholderMock.cls
- Provides mock responses for testing
- Demonstrates proper test data structure
- Located in
force-app/main/default/classes/
-
JSONPlaceholderExerciseTest.cls
- Contains test methods to validate your implementation
- Shows proper test method structure
- Located in
force-app/main/default/classes/
- Clone this repository to your local machine
- Deploy the code to your Salesforce org using:
sfdx force:source:deploy -p force-app/main/default
- Open
JSONPlaceholderExercise.cls - Implement each method following the TODO comments
- Use the JSONPlaceholder API (https://jsonplaceholder.typicode.com/)
- Run the test class to verify your implementation
Your implementation should:
- Pass all test methods in
JSONPlaceholderExerciseTest - Handle JSON properly
- Include proper error handling
- Follow Salesforce best practices
- Test your implementation against the actual JSONPlaceholder API first
- Use the Developer Console debug logs to troubleshoot
- Reference the solution in
solutions/classes/if you get stuck - Pay attention to the HTTP response status codes
Once you've completed the basic implementation, try these challenges:
- Add error handling for non-200 status codes
- Implement request timeouts
- Add bulk operations for multiple posts
- Create custom exception classes
If you need help:
- Review the solution code in the
solutionsdirectory - Check the test class for expected behavior
- Reach out to your instructor
Happy coding! 🚀
This is part of the Cloud Code Academy Integration Developer certification program.