How to debug Apex code effectively?
Question: I’m new to Salesforce development and would like to learn how to debug my Apex code effectively. I often encounter issues in my triggers and controllers but struggle to identify the root causes. What steps or tools can I use to output debug information, investigate issues, and resolve errors…
Deserializing JSON with Reserved Words as Properties in Apex
Question How to Deserialize JSON with Reserved Words as Property Names in Apex? Is there a way to deserialize JSON into an Apex object using JSON.deserialize, even if some of the property names in the JSON correspond to reserved keywords in Apex? For example, when deserializing JSON with reserved words,…
Does setting a lookup field trigger a SOQL query?
Question: When working with Apex, a common question that arises is whether creating a new record with a lookup field will trigger a SOQL query. For example, if you create a new Contact and assign it to a lookup field of a Case record, does it result in a SOQL…
Can Data Streams be created via Apex in Tests?
Question How to Test Data Stream Creation via Apex in a Test Class? I am trying to create and test Data Streams in Apex within a test class, but I’ve encountered challenges and errors during execution. Here’s the scenario: In my Apex Controller, I query for Data Streams (and other…
How to Clone a Record with Related Lists?
Question: I need to clone all Account records along with their associated Contact records. I am using the clone() method in Apex for this. Below is the code I have written: I am unable to figure out how to associate the cloned contacts with the corresponding cloned accounts. Since the…
How to Run a Scheduled Job Every 15 Minutes?
Question: Salesforce’s built-in GUI for scheduling jobs does not allow setting an interval shorter than one day. However, I need to run a scheduled job every 15 minutes. How can I achieve this in Apex? CRS Info Solutions offers industry-leading Salesforce training in Singapore with real-time projects, Salesforce training certification guidance, interview coaching, and…
Why Are Session IDs Different Across Contexts in Salesforce?
Question: I’m implementing an OAuth flow between two Salesforce instances. A challenge I’m facing is maintaining sessions when the target instance has the same instance URL as the origin instance, causing users to be logged out of the original instance upon login to the other. To address this, I’m using…
Dynamic REST API JSON Body Using Field Sets in Apex
Question: I need to construct the request body for a REST POST call in which the key (Field API Name) and its corresponding value are dynamically included in JSON format. The field API names are retrieved from a field set, and the values come from a database query. For example,…
Publishing Platform Event with JSON in a Text Field?
Question When attempting to publish a Platform Event with a valid JSON object inside a custom text field (Message__c), the serialized JSON string appears with backslashes before special characters such as double quotes (“). For example, when assigning the following JSON to Message__c: The resulting event payload contains an escaped…
CheckMarx FLS Violations for Dynamic SObjects in Apex?
Question: In Salesforce Apex, handling objects dynamically using the generic SObject type allows for flexible and reusable code that can work across different Salesforce objects. However, this dynamic approach creates challenges for static code analysis tools like CheckMarx and PMD. For example, consider the following code snippet where QuoteLineItem records…

