This assignment focuses on implementing outbound callouts from Salesforce, using Queueable Apex, and handling pagination from external APIs.
By the end of this lesson, you will be able to:
- Implement asynchronous callouts from Salesforce triggers using Queueable Apex
- Build robust API integration services with proper separation of concerns
- Implement pagination for external API callouts
- Handle error scenarios in integrations
- Create wrapper classes to deserialize JSON API responses
In this assignment, you will be implementing a News Article integration with the NewsAPI.org service. The application will synchronize news articles based on categories defined in Salesforce, using Queueable Apex processing.
Your implementation must:
- Make callouts when News Category records are created or updated with Sync set to true
- Use Queueable Apex for all operations, supporting multi-page sync
- Store the retrieved articles in Article__c custom objects
- A NewsAPI.org API key (sign up at https://newsapi.org)
- Properly configured Named Credential in your org (see Setup Instructions)
Your tasks for this assignment include:
- Implement
NewsAPIResponseclass for deserializing the API response, with a static method to convert API articles to Salesforce records - Implement
NewsAPIServiceclass for making callouts to NewsAPI, using a fixed page size - Complete the
NewsCategoryTriggerHandlerclass to handle Queueable-based callouts - Complete the
NewsCategoryQueueableclass to support paginated callouts with a maximum page limit - Make sure the trigger correctly handles both insert and update scenarios
- In Salesforce Setup, navigate to Security > Named Credentials
- Click New Named Credential
- Configure with appropriate settings for NewsAPI.org
- Save the configuration
- Test classes have been provided for you in the
force-app/main/default/classes/testsfolder. NewsCategoryTriggerHandlerTesttests the trigger handler for insert and update operations.NewsAPIServiceTesttests the NewsAPIService class for making callouts to NewsAPI.- Ensure all tests pass with proper coverage
The following are valid categories for the NewsAPI:
- business
- entertainment
- general
- health
- science
- sports
- technology
Your implementation should:
- Pass all test methods in the provided test classes
- Properly deserialize JSON responses from NewsAPI
- Create Article__c records from the API response
- Include comprehensive error handling
- Follow Salesforce best practices for integration
- Review the API documentation at NewsAPI Documentation
- Use the Developer Console debug logs to troubleshoot
- Test with mock responses before making actual API calls
- Pay attention to error handling for various scenarios
- Apex Developer Guide: Queueable Apex
- Apex Developer Guide: Callouts from Triggers
- JSON Deserialization in Apex
- Named Credentials in Salesforce
Once you've completed the basic implementation, try these challenges:
- Add support for additional search parameters
- Calculate the optimal number of pages to sync based on the API's total results
- Implement custom logging to track integration activity
- Add error handling that creates Error__c records with detailed information
If you need help:
- Review the test classes for expected behavior
- Check the documentation links provided
- Reach out to your instructor
Happy coding! 🚀
This is part of the Cloud Code Academy Integration Developer certification program.
© 2025 Cloud Code. All rights reserved.
This software is provided under the Cloud Code Developer Kickstart Program License (CCDKPL) Version 1.0. The software is licensed, not sold, and is intended for personal educational purposes only as part of the Cloud Code Developer Kickstart Program.
See the full license terms in LICENSE.md for more details regarding usage restrictions, ownership, warranties, and limitations of liability.