Category Archives : Apex

How Does Test Coverage Work for Enums and Properties in Apex?

On April 8, 2025, Posted by , In Apex,Salesforce, By ,, , With Comments Off on How Does Test Coverage Work for Enums and Properties in Apex?

Question: I recently noticed some unusual behavior in Apex test coverage and wanted to confirm whether this has always been the case or if something has changed over time. Specifically, I observed that: Consider the following class containing only an enum: Even when this enum is used in test cases,…

Loop with SOQL or List, Which is Better?

On April 8, 2025, Posted by , In Apex, With Comments Off on Loop with SOQL or List, Which is Better?

Question: When working with Salesforce Apex, is it better to use a SOQL query directly within a for loop, or to query the records into a list first and then iterate through that list? Considerations include performance, memory usage, and specific use cases. Here are two examples of the approaches…

Managing Batch Execution Without DML Limits in Salesforce

On April 7, 2025, Posted by , In Apex,Salesforce Technical Questions, With Comments Off on Managing Batch Execution Without DML Limits in Salesforce

Question How to Create Accounts with Multiple Contacts in Salesforce Without Exceeding DML Limits? I am trying to create accounts and associate 1,000 contacts with each account in Salesforce using a batch class. When managing batch execution without DML limits in Salesforce, I can successfully handle the required number of…

Can You Set Lookup Fields with __r and External IDs?

On April 4, 2025, Posted by , In Apex,Salesforce, By ,, , With Comments Off on Can You Set Lookup Fields with __r and External IDs?

Question Is it possible to set a lookup field in Apex by using the relationship field (__r) and an external ID? For example, can we relate a child record to its parent by specifying the parent object with just an external ID value? If yes, how does it work, and…

Mixed DML Operation Error in Salesforce?

On April 4, 2025, Posted by , In Apex, With Comments Off on Mixed DML Operation Error in Salesforce?

Question: I am encountering a MIXED_DML_OPERATION error when trying to perform DML operations on setup objects (e.g., Custom Settings) and non-setup objects (e.g., Lead) in the same transaction. Here’s a snippet of my test class: When running this code, I receive the following error: How can I resolve this issue…

How to resolve Record is read-only error in trigger?

On March 31, 2025, Posted by , In Apex, With Comments Off on How to resolve Record is read-only error in trigger?

Question: I am writing a trigger to populate the competitors’ names into a custom field on Opportunity. However, while testing, I am getting the following error message: System.FinalException: Record is read-only: Trigger.updateCompetitors: line 24 Here’s the trigger code I’ve written: I am encountering the error on line 24, which is…

Ghost Schedulable Jobs Blocking Deployment?

On March 25, 2025, Posted by , In Apex, With Comments Off on Ghost Schedulable Jobs Blocking Deployment?

Question: Why does Salesforce block deployments due to schedulable jobs when there are no visible pending or in-progress jobs for the associated class? I’ve cleared all schedulable jobs from the class, but the issue persists. Are there ways to handle or resolve this problem? I’ve tried querying all CronTrigger objects…

Apex Callout Fails Due to SunCertPathBuilderException?

On March 23, 2025, Posted by , In Apex,Salesforce Technical Questions, With Comments Off on Apex Callout Fails Due to SunCertPathBuilderException?

Question I am trying to make an Apex callout from Salesforce to an external system hosted inside a corporate firewall. The firewall forwards the request to a load balancer, which then routes it to the appropriate web server. While the callout works correctly when tested from SOAP UI, it fails…

How to Customize Fields in Add Products Button?

On March 23, 2025, Posted by , In Apex, With Comments Off on How to Customize Fields in Add Products Button?

Question: When I click the standard Add Products button in Salesforce (e.g., on an Opportunity), the resulting screen displays certain fields as columns, which seem to come from the Product search layout. However, after selecting products, I am taken to another screen where I want to display additional custom fields…

How to Filter Opportunity Owner ID in a Report?

On March 18, 2025, Posted by , In Apex, With Comments Off on How to Filter Opportunity Owner ID in a Report?

Question: When building a report programmatically using Apex, how can we set up a filter for “Owner ID equals” using a ReportFilter from the Reports namespace? Specifically, what is the correct column name for the Owner ID field on the standard Opportunity object? I tried the following code, but it…