39 votes
Accepted

async/await functions in LWC

async/await syntax is fully supported by LWC. However, as it was introduced in ES8, in old browsers, this syntax is transpiled down to ES5, which can cause performance issues if the code is executed ...
Oleh Berehovskyi's user avatar
30 votes
Accepted

How to use custom LWC lightning component in lightning-datatable

Step 1 : create custom component as follows. pocCustomComp.html : <template> <div> Id: {recordId} </div> <lightning-file-upload label="Upload" ...
salesforce-sas's user avatar
28 votes
Accepted

Simple example on how to use Promises to call @AuraEnabled Apex methods?

Using Promises, at least we can make it look like that in the controller: onclick : function(cmp, evt, hlp) { hlp.apex(cmp,'myServerSideAction_1',{ input : 'START-PROMISE' }) .then(...
Uwe Heim's user avatar
  • 28.3k
22 votes
Accepted

Which external Javascript libraries work with Lightning Locker Service?

Important: Libraries that do not support strict mode will not work with LockerService enabled. Salesforce is testing libraries to determine which ones currently will work with Locker Service. The ...
crmprogdev's user avatar
  • 40.9k
22 votes
Accepted

How can I quickly get today's date in a Lightning Component? (for use in an attribute)

You create an attribute and initialize it using $A.localizationService in your controller. Component: <aura:component> <aura:handler name="init" action="{!c.init}" value="{!this}" /> ...
Brian Mansfield's user avatar
21 votes
Accepted

How do I call functions loaded from a Static Resource JavaScript file?

you could attach your utility methods to the global window object(SecureWindow) and use it in your controller. Static Resource: TestScript (function(w){ "use strict"; //Optional because LC on ...
Praveen's user avatar
  • 10.1k
21 votes
Accepted

Is there a version of moment.js that works with the current Locker Service?

Just played around with the latest version of Moment.js , 2.18.1 and seems to play nicely with locker . Summer 17 whitelisted InstanceOf operator in locker API and that seems to have made Moment.js ...
Mohith Shrivastava's user avatar
20 votes
Accepted

Global Variables JS - Component Controller

You can declare those variables in helper and access them like that: ({ x: 10, y: 15, someHelperFunction: function() { console.log(this.x); } }) or from the controller: ({ ...
lesis's user avatar
  • 315
20 votes
Accepted

Array.push() won't update Lightning Web Component View

If you rebuild the array as below and reassign, the @track sees the change: this.myArray = [...this.myArray, myNewElement]; My guess is that the @track isn't noticing the original push() in the ...
DaveS's user avatar
  • 1,604
19 votes

Winter 17 release : event.getSource is not a function on lightning:button

event.getSource() is a proprietary API only available on Aura Events, so, no, you can't use that with lightning:button, just like all components from the lightning namespace, they will not rely on the ...
Caridy Patiño's user avatar
19 votes
Accepted

What are the outer parentheses in Lightning controllers?

This choice was made for two reasons. We parse the Controller and Helper on the server to validate them. There are many different Java Parsers of JSON we could use, but regardless which we choose we ...
Kris Gray's user avatar
  • 3,106
19 votes
Accepted

Is there a maximum result size for @AuraEnabled Apex methods for Lightning Aura components?

I tested three basic boundaries: total payload size, size of an element, and number of items. Total Payload Size, Element Size First, I created a map with 9 keys, each key being a 3,000,000 ...
sfdcfox's user avatar
  • 487k
17 votes
Accepted

How to send Javascript map as a parameter from lightning component to Apex server controller?

Don't use Map, just use a normal Object. Here's a demonstration: Apex: public class LightningMap { @AuraEnabled public static void doMap(Map<String, Object> values) { System.debug(...
sfdcfox's user avatar
  • 487k
16 votes
Accepted

How to use an apex class variable in LWC javascript?

There's no way at least of today to import constant values directly in JS from Apex. The only available way is to import Apex methods. You can actually utilize this for your use case here. What you ...
Jayant Das's user avatar
  • 30.5k
15 votes
Accepted

What is the difference between JSFORCE and SFORCE?

Here they are: JSforce: This is a open source plugin to allow developers to connect to Salesforce from JavaScript. Here is the list of supported methods. From documentation: JSforce (f.k.a. Node-...
Raul's user avatar
  • 18.7k
15 votes
Accepted

Scheduler Javascript Library / Component that works in Salesforce Lightning with LockerService

Standard Agenda View Using FullCalendar javascript component. You need to add these static resources: jQuery 3.3.1 Moment JS 2.22.0 FullCalendar 3.9.0 FullCalendar Scheduler 1.9.4 Lightning ...
Robs's user avatar
  • 9,330
14 votes
Accepted

Sharing JavaScript between multiple Lightning Components

Currently the recommended mechanism for this is to use a Static Resource and include it in any components that need to share the same JavaScript via ltng:require (loads the library once and only once ...
Doug Chasman's user avatar
  • 10.1k
14 votes
Accepted

Understanding $A.getcallback() usage

Aura, Lightning's runtime, has a "life cycle" that every event goes through. Everything in Aura starts with an event being fired, some controller handling that event, data propagating through any ...
sfdcfox's user avatar
  • 487k
14 votes

LWC : Events - When to use event.target.value & event.detail.value

You are talking about event reparenting. Check this question - event.getSource() alternative in LWC? (considering origin reparenting). Consider below components chain in LWC: <c:parent> &...
salesforce-sas's user avatar
13 votes
Accepted

Populate JavaScript array with results from apex methods

@Poet's answer handles most of the cases except where the StringOne contains Single quotes in it. If there is a single quote like StringOne='Lewi\'s' it will break your Javascript execution, because ...
karthikselva's user avatar
  • 2,446
13 votes
Accepted

Do promises work in Lightning?

Promises execute in a microtask which, by definition, breaks out of the Lightning event loop and the current Lightning access context. If you're unfamiliar with microtasks please read https://...
Kevin Venkiteswaran's user avatar
13 votes
Accepted

Uncaught Assertion Failed!: Descriptor for Config required for registration : undefined Callback failed

i found the error, it was very dumb... in a different component that i use there was an aura:if block that was empty and did nothing, and made everything fail. after i removed it, it worked fine
Dana Griff's user avatar
  • 1,574
13 votes
Accepted

Can we See the lwc Module?

Edit (2019-05-30): LWC is now open source! https://github.com/salesforce/lwc Our intent is to open source LWC by the end of the year but it will ultimately come down to resourcing constraints because ...
Eugene Kashida's user avatar
13 votes
Accepted

Feasibility to import entire LWC classes to access @api methods

I am not ES6+ or JS expert, but there's a section for this on the documentation - Share JavaScript Code and also there are examples on lwc-recipe for this. In general, the export works as documented ...
Jayant Das's user avatar
  • 30.5k
13 votes

(LWC) - Lightning Datatable: Custom Data Types

Below I described step by step how you can do it. For more details and code you can check the following post: Custom Types in LWC Lightning Datatable Create a Custom Data Type component customTypeA/...
Piotr Gajek's user avatar
  • 2,595
12 votes
Accepted

Lightning Components: How to make sure that a script loaded via ltng:require is loaded in aferRender()?

As per @TrevorBliss comments , adding afterScriptsLoaded to the ltng:require is sufficient which means there's no need for the renderer. If you really need to do this in the renderer, then you need ...
Praveen's user avatar
  • 10.1k
12 votes
Accepted

Examples of use of getValueProvider

Custom Value Providers really doesn't have any place in Lightning, as addValueProvider is used by the framework to provide $Label, c, v, etc. Dynamic component creation is facilitated by $A....
sfdcfox's user avatar
  • 487k
12 votes
Accepted

pass Map as parametre from lwc to apex

There's a few things that I can see. For starters your first example has "map" defined as an array: @track myMap = []; Your second uses the JS Map object which will not map to anything in ...
gNerb's user avatar
  • 9,471
12 votes
Accepted

Select Child Component in LWC when it is present multiple times

When you have multiple child components called inside a parent and you want to query a specific component, you can do it via various ways:- using HTML data-* Attribute let's say a parent is having ...
sanket kumar's user avatar
  • 15.2k
11 votes
Accepted

Enqueued action not executed in Lightning Component

Okkaaaaay evreyone, I did it. So first I moved my code from helper to controller. Then I noticed something strange (that I forgot to mention in the first place) : in the console, "fired 2!" was ...
Julien Gaïotto's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible