Skip to main content

Posts

Showing posts with the label null

Latest Post

Custom Metadata Types vs Custom Settings vs Custom Labels

  Custom Metadata Types vs Custom Settings vs Custom Labels 💬 In plain words:  Three lookalikes: Custom Metadata = configuration that DEPLOYS with your code (best for app settings). Custom Settings = org/user-specific values, changeable at runtime (hierarchy type is great for bypass switches). Custom Labels = translatable text for the UI. 📌 Example:  API endpoint URLs per environment → Custom Metadata (deploys with code, sandbox vs prod values). A 'Bypass_Automation__c' checkbox an admin flips during data load → hierarchy Custom Setting. The word 'Submit' translated to Hindi → Custom Label. 🎬 Real-Life Example: The Fee Table Trapped Inside Code  Skyline charges a different delivery fee per city. Apex needs those rates on every booking. The Old/Bad Way:  if (city == 'Delhi') fee = 50. Else if (city == 'Mumbai') fee = 65. … Every rate change is a code change, a test run, and a deployment. Why this is bad:  Business data is trappe...

Handling Null Pointer Exceptions in Salesforce Apex

Introduction: Null Pointer Exceptions are common errors that developers encounter when working with Apex code in Salesforce. These exceptions occur when a variable is null, and an attempt is made to access or perform an operation on it. In this blog post, we will explore the causes of Null Pointer Exceptions in Salesforce Apex and discuss best practices for handling them effectively. Table of Contents: Introduction What is a Null Pointer Exception? Causes of Null Pointer Exceptions Best Practices for Handling Null Pointer Exceptions      a. Null Check before Accessing Variables      b. Use Conditional Statements      c. Debugging and Logging      d. Defensive Programming Exception Handling in Salesforce Apex Conclusion What is a Null Pointer Exception? A Null Pointer Exception, often abbreviated as NPE, occurs when a program attempts to access or perform an operation on a null object or variable. In Salesforce Apex, null ...

Safe Navigation Operator (?.) in salesforce

 Now we have a useful operator in salesforce to avoid the null exceptions. Use the safe navigation operator  (?.) to replace null checks. it's very useful to reduce lines of code and increase test class performance.  Before Safe Operator String profileUrl = null ; if ( user . getProfileUrl ( ) != null ) { profileUrl = user . getProfileUrl ( ) . toExternalForm ( ) ; } After Safe Operator String profileUrl = user . getProfileUrl ( ) ?. toExternalForm ( ) ; instead of 4 lines Now we can make one line for this. Code looks more  readble.

Popular Posts

Salesforce LWC Code for Multi-Select Lookup

Introduction: In Salesforce Lightning Web Components (LWC), implementing a multi-select lookup field can enhance the user experience and provide greater flexibility for selecting multiple related records. In this blog post, we will walk through the process of creating a multi-select lookup field using LWC. We will cover the required code snippets and provide step-by-step instructions to help you implement this functionality in your Salesforce org.