35
votes
Accepted
Help me to undestand this lightning helper methods (reduce & showHelpMessageIfInvalid)?
1 reduce - what this function will do
The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
Read here for ...
18
votes
Accepted
Helper method error: says is "Not a function"
I think the problem is with your doInit function. The helper is passed to the function as the third argument:
doInit : function(component, event, helper){
14
votes
How to call helper method from a different lightning component?
There are basically two ways to do this.
Option 1: Extend a Component
You can extend an extensible component to share helper methods.
BaseCmp
BaseCmp.cmp
<aura:component extensible="true">
&...
8
votes
Accepted
Helper Method undefined when called from dynamically created component
Aura framework calls the controller method with three arguments in exact order:
handlePress : function(component, event, helper) {
console.log('pressed');
helper.helperMethod(cmp);
}
And you ...
8
votes
Accepted
Check if certain string exist in my enum values - salesforce
You can use the values method to get all values of enum, then check name of each in loop.
Set<String> enumNames = new Set<String>();
for (KeyValues keyValue : KeyValues.values()){
...
5
votes
Show checkbox while loading component
component.find() returns one of three types of value:
If the local ID is unique, find() returns the component.
If there are multiple components with the same local ID, find() returns an array ...
5
votes
Accepted
Lightning Helper how to include js files?
See Using External JavaScript Libraries. Basically, you can include the file, and then call a script after it loads. I've included the example from the manual below. As you can see, once imported, ...
4
votes
Accepted
calling helper method from inner function in another helper function (same helper) in lightning component
You need a reference outside the inner function to this:
// in outer function
var self = this;
...
self.func2(component);
When a method is called, "this" is typically set to the object that called ...
4
votes
Accepted
Lightning updating 2 attributes when only 1 is updated
This is the nature of object oriented programming. An object holds a collection of values. However, the variable itself simply holds a reference to the object. This means that when you reuse the same ...
4
votes
Show checkbox while loading component
component.find() returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my ...
4
votes
Accepted
Helper method not calling other helper method
window.setTimeout will run in a Global Context and thus this will point to that context. To be able to utilize this in Function Context (which is foo in this case), you will need to assign the local ...
4
votes
Accepted
Show/Hide of a div doesn't work sometimes
What you implemented is fine. I assume it could be because of cache issue. However, the way you implemented is not the best practice per-se. You should be using aura:if.
Below is how it would look ...
4
votes
Accepted
run quick action from batch
You can execute Quick Actions in Apex code via the QuickAction class.
Specifically, you call the static method performQuickAction() with an instance of QuickActionRequest that defines what you want to ...
3
votes
Accepted
helper method is called recursively
When your helper is getting called recursively, it means you have a method name conflict between the client and server, which, in this case, appears to be getOpportunities. You should probably have a ...
3
votes
Accepted
Can I avoid a code duplication here?
You can use shortcircuit boolean expression to your advantage.
public with sharing class JobHelper {
List<Task> taskList = new List<Task>();
public void ...
3
votes
Can I avoid a code duplication here?
The insertHandler method should be outside of the for loop entirely. Aside from that, I really don't see any point in trying to optimize your code. If you had a ton of different values, you might use ...
3
votes
Dynamic Button Icons in a Data Table Similar to Dynamic Actions in a Data Table
Forget emulating the data table with dynamic actions. Instead:
Controller
init : function(component, event, helper) {
component.set('v.caseColumns', [
{type: 'button-icon', ...
3
votes
Accepted
Lightning Application Event Seems to Refuse to Fire
JavaScript is case sensitive. The correct method name is "getParam", not "getparam." Note that, since you're getting this error, that means that your event is indeed firing. Also, once you've ...
3
votes
Accepted
JSON parsing and aura iteration in salesforce Lightning
If your Apex class returns the Object in String format, then You Just do JSON.parse("Your_return_String") to get as an Object.
EDIT:
You have not set Attribute value to 'newassets'.component.set('v....
3
votes
Packaging custom labels used in lightning helpers and controllers
As SFDC platform is unable to parse lightning components to see which custom labels are used, you can create a dummy apex class where you call them to create apex dependencies ( so include them in ...
3
votes
Accepted
Use existing Lightning component in $A.createComponent
The mistake is at passing attribute value to pageComponentCard "component":"{!v.cardId}", {!v.cardId} it is used in component markup . you must use component.get("v.cardId") to get attribute value.in ...
3
votes
Adding onclick to dynamically created button
I just did something like this the other day. Not sure if it meets all your needs but it at least illustrates the concept
Component Controller
({
doinit: function(component,event,helper){
<...
3
votes
Salesforce Simple Syntax Error
There is a extra parenthesis in dolayout helper method
var data = response.getReturnValue());
Also from your browser console if you click into the error it will show the exact line where the code ...
3
votes
Accepted
Is it OK to have variables in a Lightning Component Helper
Don't store data in the helper. While it's not explicitly forbidden, the documentation does not specify that it is safe to store data in the helper, so you should make no assumptions that it is until/...
3
votes
Is it OK to have variables in a Lightning Component Helper
Someone from the Aura team might chime in with a more definitive answer; however, I think that helper variables are acceptable in certain situations. You have to be careful though as helpers are ...
3
votes
Accepted
Map<String,wrapper> returned from apex class, not received by the helper controller!
In Lightning, you must use @AuraEnabled in order to have the data be serialized.
public class unitDetails {
@AuraEnabled public Integer activeUnits;
@AuraEnabled public Integer neverUnits;
...
3
votes
Access Object in Apex Class / Method after passing it from Controller
Because your sObj is of type Map<String, Object>, so to access the values within the map, you will need to fetch the values based on the key.
As an example (as in your screenshot), to fetch the ...
3
votes
Accepted
Restrict overlapping dates of Opportunities with Trigger
After looking over the code you've provided, I'm not seeing anything jump out as being obviously wrong with the if statement for determining overlapping dates.
I have some concerns about a few parts ...
3
votes
Accepted
How to get reference to Component from inside an event method
You can bind it to the function call. You'd want to make the following changes:
// Helper function
handleMessage: function (cmp, event) {
console.log('handleMessage');
console.log(JSON.parse(...
3
votes
Accepted
How to call a method in a lightning component in same helper
I think this should do it:
callbackOnceAfterDelay : function(cmp, helper) {
const self = this;
const delay=60000; //1 min
setTimeout(function() {
console.log('Inside delay: ');
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
helper × 87lightning-aura-components × 53
apex × 21
javascript-controller × 16
trigger × 13
lightning × 13
javascript × 12
controller × 12
aura × 12
after-trigger × 7
lightning-web-components × 4
class × 4
lightning-apps × 4
soql × 2
unit-test × 2
lightning-experience × 2
error × 2
before-trigger × 2
error-messages × 2
lightning-events × 2
aura-attribute × 2
onclick × 2
js × 2
trigger-oldmap × 2
function × 2