Salesforce Platform Developer I (legacy) — Question 255
A business implemented a gamification plan to encourage its customers to watch some educational videos.
Customers can watch videos over several days, and their progress is recorded. Award points are granted to customers for all completed videos. When the video is marked as completed in Salesforce, an external web service must be called so that points can be awarded to the user.
A developer implemented these requirements in the after update trigger by making a call to an external web service. However, a System.CalloutException is occurring.
What should the developer do to fix this error?
Answer options
- A. Surround the external call with a try-catch block to handle the exception.
- B. Move the callout to a class that implements Queueable and Database.AllowsCallouts Interfaces.
- C. Replace the after update trigger with a before insert trigger.
- D. Write a REST service to integrate with the external web service.
Correct answer: A
Explanation
The correct answer is A because surrounding the external call with a try-catch block allows the developer to handle the System.CalloutException gracefully without causing the trigger to fail. Option B is incorrect because while using Queueable can allow callouts, it doesn't directly address the exception in the current trigger context. Option C is not suitable since changing the trigger type would not resolve the callout issue. Option D is irrelevant as creating a REST service does not pertain to fixing the existing callout problem.