Posts

Use Lightning Data Service in Lightning Web Components

What Is Lightning Data Service? Lightning Data Service (LDS) is a powerful tool designed for Lightning Components, offering functionality similar to that of the Visualforce standard controller. It simplifies data handling, is cost-effective, and provides lightning-fast performance. With LDS, records are loaded once and then cached, allowing all components that use the same record to share it seamlessly. This means that any updates made in one component are instantly reflected in all other components using that record, all without the need for Apex code. How to Use Lightning Data Service To get started with Lightning Data Service, follow these steps: Step 1: Create a Lightning Web Component Use the Salesforce CLI to create a new Lightning Web Component. SFDX: Create Lightning Web Component Step 2: Name Your Web Component Choose a name for your web component and open the component's HTML file. Step 3: Add the HTML Code In your myPage.html file, add the following code to utilize the ...

Best Practices for Creating Salesforce Roll-Up Summary Triggers

Understanding the Use of Roll-Up Summary Fields in Salesforce Roll-up summary fields are a powerful feature in Salesforce that allow you to automatically display calculated values on a master record based on the related detail records. These detail records must be linked directly to the master record through a master-detail relationship. With roll-up summary fields, you can perform various calculations, such as totals, counts, and averages, making it easier to track important metrics related to your data. Why Use Roll-Up Summary Fields? Roll-up summary fields provide several benefits: Automated Calculations: They automatically update whenever related detail records are created, updated, or deleted, ensuring your master record reflects the most current data. Data Integrity: By consolidating information from related records, roll-up summary fields help maintain data integrity and accuracy within your Salesforce org. Improved Reporting: They enhance your reporting capabilities by summa...

Setting Up Your Salesforce DX Environment and Creating Your First Lightning Web Component

What is Salesforce DX? Salesforce DX (Developer Experience) is a powerful development environment that allows for better source-driven development and collaboration. A Salesforce DX project features a specific structure and a configuration file that designates the directory as a Salesforce DX project. The "DX" stands for Data Transfer, indicating the project's focus on efficiently managing and transferring data. Salesforce DX introduces a new project structure for your organization’s metadata (including code and configuration), templates, sample data, and tests. By utilizing a version control system (VCS), teams can ensure consistency throughout the development process. Setting Up Salesforce DX for the First Time Prerequisites Before you begin, ensure you have the following items installed: Salesforce CLI Visual Studio Code (along with necessary extensions) Step 1: Install Salesforce CLI Download the Salesforce CLI executable files from the following links: Windows 32-bi...

Resize Lightning Field Label: Modify Font Size

When working with Lightning Components in Salesforce, you may want to customize the appearance of field labels, including their font size. In this post, we’ll go through the steps to modify the font size of a Lightning field label effectively. Step 1: Create Your Lightning Component First, let’s create a simple Lightning component with a lightning:select field. This will serve as our example where we will modify the label size. < aura:component > < lightning:select name = "select1" label = "How many tickets?" required = "true" > < option value = "" > Choose one... </ option > < option value = "1" > One </ option > < option value = "2" > Two </ option > < option value = "3" > Three </ option > </ lightning:select > </ aura:component > Explanation: The lightning:select component is created wi...

How to Implement a Lightning Component with Apex Controller

In this blog post, we will walk through the steps required to implement a Lightning Component that retrieves and displays a list of contacts from Salesforce using an Apex controller. Step 1: Implement an Apex Controller First, we need to create an Apex controller that will handle the server-side logic for fetching contacts. The following code defines a simple class named ContactsController : public class ContactsController { @AuraEnabled public static List<Contact> getContacts() { return [SELECT Id, Name, Email FROM Contact ORDER BY CreatedDate ASC]; } } Explanation: The @AuraEnabled annotation makes the method accessible to Lightning Components. The method getContacts performs a SOQL query to retrieve the contact records, sorting them by creation date in ascending order. Step 2: Implement the JavaScript Controller Next, we need to create the JavaScript controller for our Lightning Component. This controller will call the Apex method to fetch the c...

Common Salesforce Lightning Questions and Answers

Q1: How do I load external JavaScript and CSS libraries into Lightning Components? A: The ltng:resource component simplifies loading third-party JavaScript and CSS into your Lightning Components. Here’s the syntax to use: < ltng:require styles = "/resource/bootstrap" scripts = "/resource/jquery,/resource/bootstrapjs" afterScriptsLoaded = "{!c.jsLoaded}" /> Q2: What are the different Salesforce Lightning interfaces? A: Some commonly used Salesforce Lightning interfaces include: force:hasRecordId force:appHostable flexipage:availableForAllPageTypes flexipage:availableForRecordHome force:lightningQuickAction Q3: What is Aura in Salesforce Components? A: The Aura Components programming model is based on the open-source Aura framework, which allows you to build applications independently of your data stored in Salesforce. Q4: What is Salesforce Lightning Conditional Markup? A: Conditional markup in Salesforce Lightning can be mana...

Troubleshooting Error: Mixed DML Exception in Salesforce

What is a Mixed DML Exception? The Mixed DML Exception occurs in Salesforce when you attempt to perform DML operations on both non-setup objects (such as Account or Contact) and setup objects (like User or Group) within a single transaction. This restriction is in place because Salesforce does not allow mixing these two types of operations to maintain data integrity. Why Are You Seeing This Error? If you encounter a Mixed DML Exception, it indicates that your code is trying to modify records from both categories in one go. This often happens in scenarios where you’re creating or updating user records while also handling other standard or custom objects. How to Avoid This Error To prevent Mixed DML Exception errors in your Salesforce development, consider the following strategies: 1. Use @future Annotation Apex class code executes synchronously, meaning it processes actions in the order they are called. To perform DML operations on Salesforce sObject records asynchronously, utilize t...

Troubleshooting Error: "System.LimitException: Too many SOQL queries: 101"

What Does This Error Mean? If you've encountered the error System.LimitException: Too many SOQL queries: 101 , you're not alone. This error commonly occurs in Salesforce development and signifies that you've exceeded the governor limit for SOQL queries. In Salesforce, the limit for synchronous transactions is 100 SOQL queries , while for asynchronous transactions, the limit is 200 . It's important to note that all SOQL queries executed within triggers fired from a single call or context contribute to this limit. Therefore, if your code is running multiple queries within triggers or loops, you may quickly reach this threshold. How to Avoid This Error To prevent this error and ensure your code runs efficiently, consider the following best practices: 1. Follow Apex Code Best Practices Always adhere to the best practices for writing Apex code. This includes optimizing your queries and structuring your code effectively to manage governor limits. 2. Avoid SOQL Queries Inside ...

Best Practices for Writing Efficient Apex Code in Salesforce. Most Important Points for a Salesforce Developers 😀

When developing in Salesforce, it’s essential to follow best practices for writing efficient and effective Apex code. This not only ensures better performance but also helps you avoid common pitfalls that can lead to governor limit exceptions or deployment errors. Here are ten best practices to keep in mind: 1. Bulkify Your Code Always ensure that your code can handle multiple records simultaneously. This means using collections and avoiding single-record operations to enhance performance. 2. Avoid SOQL Queries and DML Operations Inside FOR Loops Never place SOQL queries or DML statements (such as update, insert, or delete) within a for loop. Doing so can lead to hitting governor limits quickly, as Salesforce imposes strict limits on the number of SOQL queries and DML statements that can be executed in a single transaction. 3. Bulkify Code for Helper/Utility Methods Design your helper or utility methods to handle collections of records. Use collections such as Lists, Sets, Maps, or Arr...

Metadata Types That Cannot Be Deployed or Retrieved with Metadata API in Salesforce

When working with Salesforce, understanding the limitations of the Metadata API (such as ANT and Eclipse) is crucial for effective deployment and management of your organization’s metadata. Below is a comprehensive list of metadata types that cannot be deployed or retrieved using the Metadata API and must be updated manually: Metadata Types Requiring Manual Updates Account Teams Activity Button Overrides Analytic Settings Automated Case User Settings Auto-number on Customizable Standard Fields Calendars Campaign Influences Case Contact Roles Case Feed Layouts Case Team Roles Console Layouts Multiline Layout Fields for Contract Line Items Currency Exchange Rates Data Category Visibility Settings Delegated Administration Divisions Fiscal Year File Upload and Download Security Settings Lead Settings Live Agent Chats Routed with Omni-Channel Mail Merge Templates Mobile Administration Mobile Users and Devices Multiline Layout Fields for Opportunity Teams Offline Briefcase Configurations Opp...

Connecting Salesforce with External Data Sources: SAP, AWS, Oracle, AZURE, and More.

Image
Connecting Salesforce with external data sources allows you to access and manipulate data from outside your Salesforce org. Here’s a step-by-step guide on how to set it up. Step 1: Login to Salesforce Org Navigate to Setup : Click on the gear icon in the top right corner of the Salesforce interface and select Setup . Quick Find Box : In the Quick Find box, type External Data Sources . Step 2: Create a New External Data Source Select External Data Sources : Click on External Data Sources from the search results. New External Data Source : Click on the New External Data Source button. Step 3: Fill in the Required Details Connect Salesforce with External Data Sources : Enter the necessary details for the external data source. Refer to the screenshot below for guidance. Click on Save : Once you have filled in all required fields, click Save . Step 4: Validate and Sync Click on Validate and Sync : After saving, click on the Validate and Sync button to establish a connectio...

2019 Top Salesforce Interview Questions

If you're preparing for a Salesforce interview, it's crucial to familiarize yourself with commonly asked questions. Below are some of the top questions you might encounter, along with concise answers to help you prepare. Q1: Can we call a future method from a future method? A: No, you cannot call a future method from another future method. However, you can call a Queueable from a future method. If there is no dependency between two future methods, they can be executed sequentially from the original class. Q2: What is the view state in Salesforce? A: The view state in Salesforce refers to an encrypted, hidden form field in Visualforce pages that maintains the state of the page, including component values, field values, and controller state. Q3: What is meant by callout in Salesforce? A: An Apex callout allows Apex code to integrate tightly with external services by making HTTP requests or calling Web services. Salesforce supports both SOAP and RESTful services. Q4: What is th...

Troubleshooting Error: Component Class Instance Initialization Error in Salesforce Lightning

Image
If you're working with Salesforce Lightning and encounter the error message: Error: Component class instance initialization error [Cannot read property 'g' of undefined] you're not alone. This error often arises from a mistake in the doInit event handler configuration in your component. Let's delve into the issue and how to resolve it. Understanding the Error The error is triggered when the doInit action is called improperly. In this case, it happened because of a custom event name defined in the <aura:handler> tag. Let’s take a look at the problematic code: Original Code < aura:component controller = "skb_bugSolving1" > < aura:attribute name = "myAccount" type = "Account[]" /> < aura:handler name = "getAccount" value = "{!this}" action = "{!c.doInit}" /> < div class = "demo-only" style = "width: 320px;" > </ d...

Troubleshooting Error: Unknown Controller Action 'doInit' in Salesforce Lightning

Image
If you’ve encountered the error message: Error : Unknown controller action 'doInit' you’re not alone. This error commonly occurs when using the doInit event in Salesforce Lightning components. Let’s explore why this happens and how to fix it. Understanding the Error The doInit event is automatically fired when a Lightning application or component is initialized, prior to rendering. This means that when the page loads, the doInit event is triggered and the system looks for the corresponding JavaScript function in the component's controller. If the JavaScript controller does not contain a valid doInit function, you will encounter the "Unknown controller action 'doInit'" error. This highlights the importance of ensuring that your controller is properly set up to handle this event. Key Takeaway Whenever you use the doInit event in your Lightning component, it’s crucial to define a valid doInit function in your JavaScript controller. Failing to do so w...