Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

New answers tagged

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({...
user avatar
  • 430k
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' }, ...
user avatar
  • 131
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 ...
user avatar
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 ...
user avatar
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, ...
user avatar
  • 430k
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, ...
user avatar
  • 430k
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="...
user avatar
  • 430k
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' }, });
user avatar
  • 741
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 - <...
user avatar
  • 116
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 ...
user avatar
  • 430k
0 votes

Spread Operator Usage in LwC

Use this: var arrObj1 = JSON.parse(JSON.stringify(arrObj));
user avatar
  • 741
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 ...
user avatar
  • 1,048
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" }, { ...
user avatar
  • 741
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" ...
user avatar
  • 96
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: %%[ ...
user avatar
  • 16.9k
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() ...
user avatar
  • 430k
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 ...
user avatar
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.
user avatar
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 ...
user avatar
  • 430k
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....
user avatar
  • 2,060
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() ...
user avatar
  • 741
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 ...
user avatar
  • 1,204
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)
user avatar
  • 13
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 ...
user avatar
  • 430k
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 ...
user avatar
  • 430k
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 ...
user avatar
  • 430k
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(...
user avatar
  • 430k
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: ...
user avatar
  • 741
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 ...
user avatar
  • 116
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 ...
user avatar
  • 17.5k
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 ...
user avatar
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 ...
user avatar
  • 19.2k
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 ...
user avatar
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 ...
user avatar
  • 430k
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....
user avatar
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 ...
user avatar
  • 1,048
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 ...
user avatar
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 ...
user avatar
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}"> &...
user avatar
  • 741
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/...
user avatar

Top 50 recent answers are included