Which One Is Better: Loop with SOQL or Create a List Then Loop?
Question Which Approach Is Better for Performance: Using a SOQL For Loop or Querying into a List and Then Looping? In some triggers, I’ve seen the following code pattern: In other cases, the code is written like this: From a performance perspective, are these two approaches the same? Which one…
Restrict Contact Deletion Based on User and Account Field Matching in Salesforce
Question: How can I ensure that a Salesforce user can delete a Contact record only if the Contact’s Account field (Account.field__c) matches the User’s field (User.field__c)? The solution must also handle users with specific profiles. Answer: You can achieve this requirement using either Flows or Apex Triggers. Below, I’ll explain…
Checkmarx FLS Create Issue for Lead Convert?
Question: I am converting a Lead using Apex in my managed package with the following code: However, Checkmarx is throwing an FLS (Field-Level Security) Create error. I know that for normal insert operations, I can resolve this by using Database.insert(records, AccessLevel.USER_MODE), like this: How can I remove the Checkmarx FLS…
Where Should I Start Learning Salesforce Development?
Question: I want to start learning Salesforce development, but there are so many topics like Objects, Classes, Apex, Visualforce, SOSL, SOQL, and Triggers. With so many options available, I am unsure which topic to learn first and how to progress step by step to gain proficiency in all aspects of…
Set Lookup Relationship via Name Pointing Field?
Question Can a lookup relationship be set using the __r name pointing field when inserting a record? A well-known post by Bob Buzzard suggests that you can relate records by assigning a nested sObject with an external ID in the __r field. However, this has been debated, with some arguing…
How to Properly Use Static Variables in Apex Dynamic Queries?
Question Issue with Using Static Variables Directly in Dynamic Queries When working with dynamic queries in Apex using Database.query(), you may run into an issue when trying to reference a static variable from another class directly in the query. The following code works as expected: However, if you try to…
How to Generate Sequential Order Numbers in Salesforce?
Question: I have a requirement where orders are created by users every minute. When an order is created, it starts in the stage “Draft” and then moves through the stages “Submitted” and “Fulfilled.” I want a custom field called OrderNumber to be automatically populated in the format ABC-00001, ABC-00002, and…
Running a Batch Class from a Queueable Job
Question: I am trying to call a batch process from a Queueable job, but I am getting the following error: Method does not exist or incorrect signature: void DeliveryScheduleSync_batch() from the type DeliveryScheduleSync Here is the code inside my Queueable class: And here is the beginning of my batch class:…
How to Set “From” Address in SingleEmailMessage?
When sending emails using Salesforce’s SingleEmailMessage, many developers encounter the challenge of setting a specific “From” address. By default, Salesforce uses the email address of the user triggering the email as the “From” address. However, there are methods to override this behavior and set “From” Address in SingleEmailMessage. Let’s explore…
Understanding Salesforce Apex Batch Results Sorting
Question: While reviewing the Salesforce release updates, I noticed the update titled “Sort Apex Batch Action Results by Request Order”. I couldn’t find much information about what exactly this means. Specifically, what are Apex batch action results? How does this change affect batch operations in Apex? If possible, can you…

