Building a REST API integration in Apex can be both exciting and challenging.
Done right, and you have a reliable integration that is easy to debug and maintain.
We will go over 5 simple but powerful ideas (with examples) that will help you architect and build a robust integration with any external REST API and improve your apex development game.
6. #CD23 @CzechDreamin
● API class that handles API calls only
● Helper class that handles the logic
● Webhook class for receiving inbound calls
● Test class that can cover the integration
code
Use separation of concerns
Idea 1/5
API class
Handles API calls, API settings, request
and response classes
Inbound Webhook class
@RestResource : Accepts incoming calls
and events from the external system
Helper class
Handles logic of the integration
and connection between
Salesforce objects and the API
Test
class
Triggers,
LWC,
Visualforce,
Flows
7. #CD23 @CzechDreamin
● API class that handles API calls only
● Helper class that handles the logic
● Webhook class for receiving inbound calls
● Test class that can cover the integration
code
Use separation of concerns
Idea 1/5
API class
Handles API calls, API settings, request
and response classes
Inbound Webhook class
@RestResource : Accepts incoming calls
and events from the external system
Helper class
Handles logic of the integration
and connection between
Salesforce objects and the API
Test
class
Triggers,
LWC,
Visualforce,
Flows
8. #CD23 @CzechDreamin
● API class that handles API calls only
● Helper class that handles the logic
● Webhook class for receiving inbound calls
● Test class that can cover the integration
code
Use separation of concerns
Idea 1/5
API class
Handles API calls, API settings, request
and response classes
Inbound Webhook class
@RestResource : Accepts incoming calls
and events from the external system
Helper class
Handles logic of the integration
and connection between
Salesforce objects and the API
Test
class
Triggers,
LWC,
Visualforce,
Flows
9. #CD23 @CzechDreamin
● API class that handles API calls only
● Helper class that handles the logic
● Webhook class for receiving inbound calls
● Test class that can cover the integration
code
Use separation of concerns
Idea 1/5
API class
Handles API calls, API settings, request
and response classes
Inbound Webhook class
@RestResource : Accepts incoming calls
and events from the external system
Helper class
Handles logic of the integration
and connection between
Salesforce objects and the API
Test
class
Triggers,
LWC,
Visualforce,
Flows
10. #CD23 @CzechDreamin
● API class that handles API calls only
● Helper class that handles the logic
● Webhook class for receiving inbound calls
● Test class that can cover the integration
code
Use separation of concerns
Idea 1/5
API class
Handles API calls, API settings, request
and response classes
Inbound Webhook class
@RestResource : Accepts incoming calls
and events from the external system
Helper class
Handles logic of the integration
and connection between
Salesforce objects and the API
Test
class
Triggers,
LWC,
Visualforce,
Flows
15. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Loading
16. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Loading
17. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Loading
18. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Loading
19. #CD23 @CzechDreamin
● Custom metadata with base urls and
credentials
● The API class can extract the information
from the custom metadata type
Idea #2
Idea 2/5
Make everything configurable
24. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Make everything configurable
3. Loading
25. #CD23 @CzechDreamin
● Log outbound calls
● Log inbound calls
● Make sure to log failures
Idea #3
Idea 3/5
Log every call
28. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Make everything configurable
3. Log every call
4. Loading
29. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Make everything configurable
3. Log every call
4. Loading
30. #CD23 @CzechDreamin
● Callouts WILL fail, it’s just a matter of time
● Show it in the interface (synchronous integrations)
● Warning to an admin (asynchronous integrations)
○ Slack
○ Chatter
○ Email
● Automatic retry (asynchronous integrations)
Salesforce
API
Idea 4/5
Handle API Failures
31. #CD23 @CzechDreamin
● Callouts WILL fail, it’s just a matter of time
● Show it in the interface (synchronous integrations)
● Warning to an admin (asynchronous integrations)
○ Slack
○ Chatter
○ Email
● Automatic retry (asynchronous integrations)
Idea 4/5
Handle API Failures
32. #CD23 @CzechDreamin
● Callouts WILL fail, it’s just a matter of time
● Show it in the interface (synchronous integrations)
● Warning to an admin (asynchronous integrations)
○ Slack
○ Chatter
○ Email
● Automatic retry (asynchronous integrations)
Idea 4/5
Handle API Failures
35. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Make everything configurable
3. Log every call
4. Handle API failures
5. Loading
36. #CD23 @CzechDreamin
● A set of objects and classes that gives you a
head start in future integrations
API class
Handles API calls, API settings, request
and response classes
Inbound Webhook class
Accepts incoming calls and events from
the external system
Helper class
Handles logic of the integration
and connection between
Salesforce objects and the API
Test
class
Triggers,
LWC,
Visualforce,
Flows
Idea 5/5
Build yourself a framework
38. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Make everything configurable
3. Log every call
4. Handle API failures
5. Build yourself a framework
39. #CD23 @CzechDreamin
5 key ideas for robust and flexible REST API integrations
1. Use separation of concerns
2. Make everything configurable
3. Log every call
4. Handle API failures
5. Build yourself a framework
40. #CD23 @CzechDreamin
Resources
● Github Repository: https://bit.ly/3W5bEvh
● Slides: https://bit.ly/42UBwwB
● My Twitter: @Lucian_Ciobanu
● My LinkedIn: https://bit.ly/3W50TJj