New answers tagged javascript
2
votes
how to call two functions in one onclick in lwc?
You can call both methods at once with Promise.all:
async handleSearch() {
const searchKey = this.key;
const [accounts, contacts] = await Promise.all([
getAccounts({ searchKey }), getContacts({...
0
votes
Jsforce where clause having multiple conditions not working
For anyone (like me) who comes along looking for a way to do this without having to build a string query, this can be achieved like so:
connection.sobject('Campaign')
.find({
Type: { $eq: 'Test' },
...
1
vote
Accepted
lightning message service not working
The problem was that the components are on different pages. In this case the messaging would not work as it is explained in this Q&A:
Lightning Message Service doesn't work between community ...
0
votes
How to Refresh or re render DIV in lwc
If I understand your question correctly, you can do this by using conditional rendering. Encapsulate your div with
<template if:true={isUploaderVisible}></template>
Make isUploaderVisible ...
1
vote
Accepted
LWC - getObjectInfo not working
The example is wrong in several places. First, the variable is declared twice, which is a bad practice. Second, the data property will be undefined the first time your getter is called. Third, ...
1
vote
Accepted
How to access an Apex Map in LWC JS
To access the first element, the access would look like this:
let firstMortageAccount = this.addressesAndMortgageAccounts[
'Address__c:{Id=a0L25000005W8rKEAS, Address_Line_1__c=Test Street, ...
1
vote
Accepted
How to trigger a HREF tag from JavaScript in LWC
You just need to use innerHTML.
import { LightningElement } from "lwc";
export default class App extends LightningElement {
renderedCallback() {
const content = '<a href="...
1
vote
Accepted
NavigationMixin not working on community
For comm__namedPage use the name attribute
this[NavigationMixin.Navigate]({
type: 'comm__namedPage',
attributes: {
name: 'energie_test__c'
},
});
0
votes
How to remove the Unwanted string from my Iframe tag it only show's up in the chrome browser?
It'll be easier to point the correction if you can share the code where you have your iframe. However, for apex iframe the attribute title is used to set the title of your document.
For Example -
<...
1
vote
Spread Operator Usage in LwC
The spread operator is a shallow copy operation. That means that while the arrays are separate objects, they both refer to the same element in every index. Let's provide a very simple example that ...
0
votes
2
votes
Spread Operator Usage in LwC
This is answered on stackoverflow. As per mozilla documentation
Don't use console.log(obj), use
console.log(JSON.parse(JSON.stringify(obj))).
This way you are sure you are seeing the value of obj at ...
0
votes
Multi column sorting in lightning web components
Suppose you have an Array of Users with properties firstName and lastName.
let userArray = [
{
firstName: "Shaun",
lastName: "Hall"
},
{
...
2
votes
Accepted
Hide/Show columns of lightning-datatable in Lightning Web Components
The only thing you need to do is removing the desired element from the columns array, or use the original set if you want it back.
<template>
<lightning-input type="toggle"
...
0
votes
Accepted
Pass a variable from AMPscript block to Client side JS?
You can just print the ampscript variable where you normally set a client-side javascript variable. In the below example, I set the cid to the contactId ampscript you already declare in the top:
%%[
...
0
votes
Accepted
LWC Set Interval function not working when used inside a wire function
// If the count down is finished, reset to Zero
let day = new Date(this.deadline);
let ddate = day.getTime();
console.log(">>>ddate getTime() " + ddate); //getTime() ...
0
votes
Lightning input type="datetime" not auto-populating values prior to 9am local time
The HTML code will work fine, You will have to make changes in your JS code
var defaultdate = new Date();
//getUTCMonth does not return preceding zero. This line will add the zero and it is ...
0
votes
Cannot use 'import' in LWC JS
You are trying to import LWC library inside AURA. If You wanna create lwc component then you cant directly do in org, you need some code editor try to use VS code Editor for Lwc component.
0
votes
Update lookup field on custom button click using Javascript
Scripts like this are rendered when the page loads, not when the button is clicked. As such, you'd want to retrieve the record first:
{!REQUIRESCRIPT('/soap/ajax/54.0/connection.js')}
let auditContact ...
4
votes
Accepted
TypeError: Cannot read properties of undefined (reading 'DOB') in for loop
When initializing your for loop to iterate through an array using its length and starting at 0 you need to use < rather than <=.
In your code you have:
for(let i=0 ; i <= this....
0
votes
How to sort records on javascript based on a nearest due date
Please use below logic:
let dateArray = [
'2022-12-30',
'2022-04-01',
'2022-05-30',
'2022-07-30',
'2022-06-30'
];
dateArray.sort((a, b) => {
return Math.abs(new Date() ...
0
votes
How to pass lightning:outputField value which is used in recordViewForm
I would say refer to this post:
How to pass Button Value on mouseover to controller Aura Component
While it does not exactly answer your question, it should lead you on the right path.
in your ...
1
vote
Why does my publication list array return undefined in Vuejs?
I figured it out that I had to stringify the subLists first: subLists = Stringify(subLists)
0
votes
how to put html body on mailto href with lwc?
Unfortunately, you can't. RFC 2368 states:
The special hname "body" indicates that the associated hvalue is the
body of the message. The "body" hname should contain the content ...
1
vote
Accepted
Update variable in a JS Static Resource
In JavaScript, each imported file is isolated by default. However, you can access any global variable, one attached to window, to work with data and methods from that file. In your case, you can use ...
2
votes
Accepted
getter vs setter in LWC
tl;dr Avoid changing data in a getter.
A getter can technically do everything a setter can do. However, performing transformations in the getter are generally a bad idea from a programming perspective ...
1
vote
Accepted
How can we define the events method in util.js or exernal js file and export that method in lwc component
For common methods that should be used in multiple places, you have three basic choices.
First, you can export the method, and then call it from your component.
let test1 = false
function handleClick(...
1
vote
How can we define the events method in util.js or exernal js file and export that method in lwc component
Create LWC of name utils.
Use utils.js as below:
export function externalFunction(event){
//function logic
//return data as per logic
}
In LWC component js file import the function to use it:
...
1
vote
getter vs setter in LWC
Getter and Setter - these are nice to have in your code but not must-have. In reality, there are many cases where programmers don't even use getter setter in the code. However in short and as per ...
1
vote
getter vs setter in LWC
Technically we can use getter and setter interchangeability and it may work but its bad for performance, it's better to do any computing in setter.
In below example, getter is called whenever the ...
1
vote
getter vs setter in LWC
You can set a property in a getter as well but it is not advisable.
The get syntax binds an object property to a function that will be called when that property is looked up. Sometimes it is desirable ...
0
votes
Accepted
Map with empty values are omitted by default
I don't know the specifics as to why key's with null values in maps are omitted when passing data to the client, but, a simple enough operation would be to convert your map to a string. Then, from the ...
0
votes
LWC : How can I make the menu folding/unfolding function? (double layer)
you need to use getter function to decide if first and second sub menu should be shown.
first sub menu will be shown if big one is clicked .(this can be done without getter also but kets use ...
1
vote
Cannot QuerySelect element inside renderedCallBack
There's nothing wrong with this in LWC directly. I even wrote a demo. However, inside Salesforce, you need to remember to use lwc:dom="manual". Note that directly manipulating innerHTML is ...
0
votes
Error: Unknown public property "name" of element <LIGHTNING-INPUT-FIELD>. This is likely a typo on the corresponding attribute "name"
Your problem is related to the fact that you are trying to pass a value to a parameter that does not exist. lightning-input-field component doesn't have the 'name' parameter
https://developer....
0
votes
Dynamically change color and font weight of text/numbers in LWC?
In your case you are trying to access this.template.querySelector(".change-color"). This returns list of div as you are iterating on list of records and you will have multiple divs with ...
0
votes
Accepted
Child component not getting re-rendered when parent component data is changed in LWC
You need to implement a setter to get this to work properly.
Currently when the value from the parent changes, nothing will happen.
In the setter you can directly call a method to run your plot data ...
0
votes
Pass values from Apex Script to LWC JS
Thanks Phil - that was helpful. I updated the LWC accordingly
import { LightningElement, wire } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getPortalMessages ...
0
votes
Open Modal Popup on Onchange in Aura Component
Use below code for your Modal
<aura:attribute name="isModalOpen" type="boolean" default="false"/>
<aura:if isTrue="{!v.isModalOpen}">
&...
0
votes
Accepted
How to track the browsing history of the visitor for my community site? Please help
You can try the following for the base level reporting. You can try using other webanalytical tools integrated with your sites. However, it is better to use google one.
https://help.salesforce.com/s/...
Top 50 recent answers are included
Related Tags
javascript × 5100visualforce × 1617
apex × 1052
lightning-web-components × 954
lightning-aura-components × 895
lightning × 527
custom-button × 326
jquery × 287
html × 221
marketing-cloud × 184
javascript-remoting × 139
aura × 132
css × 119
community × 101
controller × 96
javascript-controller × 90
button × 76
static-resources × 75
json × 74
locker-service × 73
visualforce-component × 71
lightning-experience × 69
ampscript × 66
ssjs × 65
ajax × 62