Category: Salesforce Apex
-
How to Block Recursion in Generic Trigger Handlers?
Question Blocking recursion in Apex trigger handlers is a critical concern, especially when your handler is designed to cover all trigger operations and handle SObjects of any type. Recursion occurs when a trigger causes changes that subsequently invoke the same trigger again, resulting in an infinite loop. This is particularly problematic when operations like updates…
-
How to Log Lead Inserts Without Duplicates?
Question I have a requirement to log every attempt to insert a Lead into a custom object called Lead_Log__c. This log needs to be created regardless of whether the Lead insert is successful or fails validation. To achieve this, I initially used a before insert trigger on the Lead object. However, I faced challenges with…
-
How to Return HTTP 200 in Apex REST?
Question I am new to working with webhooks and need to expose an Apex class to an external system to handle a POST operation in Salesforce. Specifically, I am integrating with Authorize.net, which requires the webhook endpoint to return an HTTP 200 status code. Here’s the screenshot of API documentation. Here’s the debug output from…
-
Why is instanceof inconsistent in Apex collections?
Question In Apex, the following behavior seems inconsistent: My Question: Answer The Apex type system, particularly regarding collections like Map, Set, and List, has certain inconsistencies that can cause confusion. Consider the following code snippet: This behavior raises the question: Why does m instanceof Map<String, Object> evaluate to true, but m instanceof Map<Object, Object> evaluates…