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
Herschel
5 days ago
I think A is the best choice. Reusable classes are key for maintainability.
upvoted 0 times
...
Luz
10 days ago
Wait, people actually consider D)? That's wild!
upvoted 0 times
...
Youlanda
15 days ago
D) is just asking for trouble, no way!
upvoted 0 times
...
Cyndy
20 days ago
C) seems like a bad idea, static resources can be tricky.
upvoted 0 times
...
Corinne
26 days ago
I disagree, B) makes more sense for clarity.
upvoted 0 times
...
Zona
1 month ago
A) is definitely the best choice for reusability.
upvoted 0 times
...
Adell
1 month ago
Including the API code directly in each class (option D) seems like a bad idea for maintainability, but I wonder if anyone would actually choose that option.
upvoted 0 times
...
Harrison
1 month ago
I feel like storing the API code as a static resource (option C) could lead to issues with updates and maintenance, but I can't recall the specifics.
upvoted 0 times
...
Charlesetta
2 months ago
I'm not entirely sure, but I remember a practice question where using separate classes for each endpoint seemed to complicate things, so maybe option B isn't the best choice.
upvoted 0 times
...
Owen
2 months ago
I think option A makes the most sense since it promotes code reuse by having a single class for the API integration.
upvoted 0 times
...

Save Cancel