Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Plat-Dev-301 Exam - Topic 2 Question 6 Discussion

To avoid duplicating code and improve maintainability, how should Universal Containers implement an API integration for code reuse?
A) Create a reusable Apex class for the API integration and invoke it from the relevant Apex classes.
B) Use a separate Apex class for each API endpoint to encapsulate the integration logic.
C) Store the API integration code as a static resource and reference it in each Apex class.
D) Include the API integration code directly in each Apex class that requires it.

Salesforce Plat-Dev-301 Exam - Topic 2 Question 6 Discussion

Actual exam question for Salesforce's Plat-Dev-301 exam
Question #: 6
Topic #: 2
[All Plat-Dev-301 Questions]

To avoid duplicating code and improve maintainability, how should Universal Containers implement an API integration for code reuse?

Show Suggested Answer Hide Answer
Suggested Answer: A

Comprehensive and Detailed 1

The fundamental principle of DRY (Don't Repeat Yourself) in Apex development dictates that logic used in multiple places should be centralized. For API integrations, this typically invo2lves creating a Utility or Service Class (Option A).

This class handles the common 'plumbing' of the integration:

Retrieving Named Credentials.

Setting headers (Content-Type, Timeout).

Standardizing error handling and logging.

Serializing and deserializing JSON payloads.

By invoking this central class from various triggers, batch jobs, or controllers, the developer ensures that any change to the API (such as a version update or header change) only needs to be made in one place. Option B leads to 'class sprawl' and duplicate boilerplate code. Option C is incorrect as Static Resources cannot contain executable Apex code. Option D is the definition of poor maintainability.


Contribute your Thoughts:

0/2000 characters

Currently there are no comments in this discussion, be the first to comment!


Save Cancel