Posts

Showing posts from February, 2019

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...