Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.
Group

Lightning Components Development

This group is for customers and partners who are using the Lightning Components. It's a forum for customers to provide feedback, requirements and share ideas. Customers may also leverage this group to collaborate with each other on best practices. This group is maintained and moderated by a salesforce.com employee(s). The content received in this group falls under the official Safe Harbor. Please also see our official Salesforce Customer Community Terms of Use

We have discovered a potential bug in the NavigationMixin but before opening a case with Salesforce Support I wanted to learn from the community if anybody else had the same experience and whether or not there is a workaround.

 

The NavigationMixin does not seem to work when used in a component which extends LightningModal. I've created a very simple reproduction which works fine when placed on a flexipage but does nothing when used in a modal dialog.

 

This is the test component's template:

<template>

<a href={url} onclick={handleAnchorClick}>Click me</a>

</template>

And this is the implementation:

import { LightningElement } from 'lwc';

import { NavigationMixin } from 'lightning/navigation';

export default class NavigationMixinTest extends NavigationMixin(

LightningElement

) {

url;

async connectedCallback() {

this.url = await this.generateUrl();

}

handleAnchorClick(event) {

event.preventDefault();

this.navigate();

}

generateUrl() {

return this[NavigationMixin.GenerateUrl](this.pageReference);

}

navigate() {

this[NavigationMixin.Navigate](this.pageReference, false);

}

get pageReference() {

return {

type: 'standard__webPage',

attributes: {

url: 'https://salesforce.com',

},

};

}

}

When rendered on a flexipage, the generated url is this:

/lightning/webpage/https%3A%2F%2Fsalesforce.com

When placed in a lightning-modal component, the url is this:

javascript:void(0);

Clicking the link whilst on a flexipage opens the Salesforce website in a new browser tab. Clicking on it when in a modal does nothing.

 

The behaviour is consistent with Lightning Web Security both on and off.

14 answers
  1. Feb 24, 1:25 AM

    it seems that unfortunately it wasn't solved yet 

    so, to call a navigation from a modal you need to add the navigation function to the modal's parent, transform the parent in 'extends navigation mixin' 

    then create a function on the modal component to call the parent's navigation 

     

    that's the only way I found that works right now

0/9000

Hello there, 

 

I wonder why the website for SLDS (

https://www.lightningdesignsystem.com

) is no longer publicly available? When I open the URL in my browser it redirects me to the Login page: 

Salesforce Lightning Design System (SLDS) website is no longer publicly available?

 

Does anybody know what is going on? How can I reference SLDS styles now?

3 answers
0/9000

As an ISV partner we still have to support both Lightning Locker as well as LWS when developing our products. Because not all customers are on LWS or on Lightning Locker and it's not a good product strategy to force the customer to update to LWS to use our components only, this would severely hinders adoption.

 

And it seems that every week there's a new thing we find that is available in major browser support, that isn't supported in Lightning Locker.

 

Recently we've had many issues for example with the AbortController to be able to abort a Fetch request. We've had to add a polyfill to our code for that. And now we've discovered that the Headers interface of Fetch is not supported in Lightning Locker... Which means another polyfill.

 

https://developer.mozilla.org/en-US/docs/Web/API/Headers <- For reference:

"This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017."

It's not like it's new either.

 

Is Lightning Locker being maintained up to date? Is everyone supposed to switch to LWS? How are we supposed to deal with this as an implementor/ISV partner? It would be nice to have an official statement about this.

22 answers
0/9000

Hi Everyone, 

 

I'm currently working on a Salesforce Task form and need some help with dynamically updating the Description field based on the Type dropdown value. Here’s a detailed breakdown of what I'm trying to achieve: 

 

### Objective: 

Automatically update the Description field in real-time when the Type dropdown value changes, without having to create a custom Visualforce page or form section. I want to perform this action within the existing Salesforce Task form interface, and it should happen automatically without requiring the user to click the Save button. 

 

### What I've Attempted: 

- I tried using JavaScript to attach event listeners to the Type dropdown and dynamically update the Description field. 

- Used Salesforce AJAX Toolkit to make real-time updates. 

- Encountered issues with DOM manipulation due to dynamically generated IDs and classes by Salesforce, causing inconsistent behavior. 

 

### Detailed Requirements: 

1. **Update Description Field**: When a user selects a type such as 'Customer Inbound,' the Description field should automatically populate with predefined text like 'Customer Inbound success.' 

2. **Existing Form**: The updates should be applied to the existing Salesforce Task form elements without creating a new Visualforce form. 

3. **Real-time Updates**: Ensure the Description field updates dynamically without the user having to click on the Save button. 

4. **Reliable Method**: Use stable selectors or another reliable method to ensure event listeners can be correctly attached and the field updated dynamically. 

 

Any guidance or solutions to achieve this within the existing form would be greatly appreciated. Thank you! 

 

0/9000

we have existing aura component which are being used as extensible component (extensible=true) Abstract component 

i have another aura component which was calling the helper method of Abstract component on button click. 

After enabling LWS in the org i am getting  

referenceError : helper is not defined 

any idea on how to resolve this issue??

3 answers
0/9000

Hi, 

 

I have a Digital Experience Site that my users interact with screen flows to create and update a Submissions__c record. I have an issue, on 1 of my screen flows portal users have the option to Cancel there submission, this uses an Action button Component on a Screen flow to trigger an auto launched flow that updates the record status field. My Issue is that if cancelled or no record then the other screen flow on the record page display messages about registering. This issue is that while the submission record is updates the other flows on the same screen are still cached so user can still view the information on the other screen.  

If they refresh the webpage then all other screen flow re-run with the updated decisions correctly. 

 

I am trying to create a process that once the user presses the Action Button to "Cancel" there Submission the autolaunched flow runs and then redirect the users to another page on the Digital Experience Site? 

OR 

after the Autolaunched flow is run then it forces a refresh of the webpage?     My main requriements are to clear the Cache so that it forces the other flows on the page to run again

 

Thanks 

 

@Salesforce Flow Automation@Lightning Web Components@* Salesforce Developers *@Lightning Components Development

5 answers
  1. Eric Smith (RafterOne) Forum Ambassador
    Jan 25, 1:47 PM

    @Callum North

     You can use this component to reactively navigate in a screen flow.  Would that help your use case? 

    https://unofficialsf.com/auto-navigate-with-screen-refresh/

0/9000

I recently created custom email component in LWC, this looked fine, but recently I received feedback that the templates which were sent from my component do not look the same as the templates they created.

So what I did is: I icluded an option to choose an Email template which current user would like to inject into lightning-input-rich-text, what I did is a renderStoredEmailTemplate().getHtmlBody() also tried renderEmailTemplate().getMergedBody() in controller of the component, so it basically retrieved proper HTML body, inspected it, checked on some online html editor, all looked the same, no issues so far. Then I passed that value to lightning-input-rich-text (the same issue in Aura), inspected the value of this field, these looked totaly different, read bit more documentation: "Pasting text enclosed in div and span tags convert those tags to p tags", ok cool but it looks like the behaviour is not as expected, also having triple spans received from HTMLValue in template made it much worse, issues I encounter so far:

- <br /> tags are also changed to p tags, so afterwards it gave me double breaks instead of single

 

- I had a span before <ul>, for some reason richTextField included it inside <ul>

 

- If I had a wrapper span and breaks inside, child spans were getting on a separate line and the styling got completelly different after break

The only option I can see right now is to show lightning-formatted-rich-text instead, but then users will not have access to modify the body of email, only to choose a template, but leaving as it is also makes this component worthless since this will not look good for our customers.

I am expecting that once I retrieve HTML body from email template and pass it to the lightning-input-rich-text I will receive the same result. Did anybody encounter the same? Cannot see anything regarding this in SF issues, nor I can find a workaround for it.

0/9000

Hi, 

 

I have a LWC that gets the files from a record and displays them with a download link, I want to update this so the "Download" link is a "Download" button that does the same actions but also the abillity to run a flow when the "Download" Button is clicked too.

 

My flow has a number of input varibale to pass data in, I can get a lot of the values from the flow my LWC sits in, but not sure how I can get the FIle name/details that has been downloaded to pass through?

 

My LWC:

 

HTML:

<template>

    <lightning-card title="Documentation">

         <template for:each={filesList} for:item="file">

             <div key={file.value} class="slds-box">

                 <div class="slds-grid slds-wrap">                     

                     <div class="slds-col slds-large-size_6-of-12 slds-medium-size_4-of-12 slds-size_1-of-12">

                       <p style="font-size: large;"><strong>FileName - </strong>{file.label}</p>

                     </div>

                     <div class="slds-col slds-large-size_6-of-12 slds-medium-size_4-of-12 slds-size_1-of-12">

                       <a style="font-size: large;" href={file.url} download>Download</a>

                     </div>

                     <!--remove Preview button-->

                     <!--

                     <div class="slds-col slds-large-size_4-of-12 slds-medium-size_4-of-12 slds-size_12-of-12">

                       <lightning-button label="Preview" 

                       variant="brand"

                      data-id={file.value}

                      onclick={previewHandler}

                       ></lightning-button>

                     </div>-->

                   </div>

             </div>

         </template>

    </lightning-card> 

    

 </template>

JS:

import { LightningElement, api, wire } from 'lwc';

import getRelatedFilesByRecordId from '@salesforce/apex/filePreviewAndDownloadController.getRelatedFilesByRecordId'

import {NavigationMixin} from 'lightning/navigation'

export default class FilePreviewAndDownloads extends NavigationMixin(LightningElement) {

//pass recordId from target in meta-xml 

    @api recordId

    @api userId

    filesList =[]

    @wire(getRelatedFilesByRecordId, {recordId: '$recordId'})

    wiredResult({data, error}){ 

        if(data){ 

            console.log(data)

            this.filesList = Object.keys(data).map(item=>({"label":data[item],

             "value": item,

             //redirect to new portal site, update "procure" with new name

             "url":`/SiteName/sfsites/c/sfc/servlet.shepherd/document/download/${item}`

            }))

            console.log(this.filesList)

        }

        if(error){ 

            console.log(error)

        }

    }

    previewHandler(event){

        console.log(event.target.dataset.id)

        this[NavigationMixin.Navigate]({ 

            type:'standard__namedPage',

            attributes:{ 

                pageName:'filePreview'

            },

            state:{ 

                selectedRecordId: event.target.dataset.id

            }

        })

    }

}

meta.XML:

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <apiVersion>62.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__FlowScreen</target>

        <target>lightningCommunity__Page</target>

        <target>lightningCommunity__Page_Layout</target>

    </targets>

    <!--enable passing in a recordId via screen flow varriable-->

    <targetConfigs>

        <targetConfig targets="lightning__FlowScreen">

            <property name="recordId" type="String" label="Input ID" />

            <property name="userId" type="String" label="User ID" />

            </targetConfig>

    </targetConfigs>

</LightningComponentBundle>

CLS:

public with sharing class filePreviewAndDownloadController {

    @AuraEnabled(cacheable=true)

        public static Map<ID, String> getRelatedFilesByRecordId(String recordId) {

            // Get record file IDs        

            List<ContentDocumentLink> files = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :recordId];

            List<ID> fileIDs = new List<ID>();

            for (ContentDocumentLink docLink : files) {

                fileIDs.add(docLink.ContentDocumentId);

            }

     

            List<ContentVersion> docs = [SELECT ContentDocumentId, FileExtension, Title 

                FROM ContentVersion WHERE ContentDocumentId IN : fileIDs];

            Map<ID, String> mapIdTitle = new Map<ID, String>();

            for (ContentVersion docLink : docs) {

                mapIdTitle.put(docLink.ContentDocumentId, docLink.Title);

            }

            return mapIdTitle;

        }

}

 

Thanks

 

@Lightning Web Components@Lightning Components Development

9 answers
  1. Dec 11, 2024, 1:28 PM

    Hi Callum,

     

    To get the logged in userid you can use this: 

    import Id from '@salesforce/user/Id';

    export default class MiscGetUserId extends LightningElement {

    userId = Id;

    }

    to get the file label, you'll need to use the dataset to get the data attribute:

    handledownload(event){

    this.createAuditLog(event);

    }

    createAuditLog(event){

    console.log('test123' + this.accountName + " file downloaded by "+ this.userId + this.recordId + this.item)

    const fields={};

    fields[AUDIT_TITLE.fieldApiName] = "File Downloaded";

    fields[PARENTID.fieldApiName] = this.recordId;

    fields[PARENTOBJECT.fieldApiName] = "NL_Tender_Opportunity__c";

    fields[AUDIT_DETAILS.fieldApiName] = event.target.dataset.filename +"file downloaded by "+ this.accountName;

    fields[USER_FIELD.fieldApiName] = this.userId;

    this blog explains how to pass data from a Flow to your LWC. https://salesforcediaries.com/2023/01/08/flow-to-lwc-pass-data-instantly/

     

    It looks like you have the structure for that set so perhaps there is an issue within your Flow. Anyway, you can get the recordId and AccountName from there.

0/9000

I added a .zip file as Static resource and I imported it on my js in this way:

import { LightningElement, api } from 'lwc';import lightbox from "@salesforce/resourceUrl/lightbox";import logoSartore from "@salesforce/resourceUrl/logoSartore";import { loadStyle, loadScript } from "lightning/platformResourceLoader";export default class CustomProductImage extends LightningElement {    @api recordId;    lightboxLoaded = false;    async renderedCallback(){        if(this.lightboxLoaded ){            return        }        await Promise.all([            loadStyle(this, lightbox + "/lightbox.css"),            loadScript(this, lightbox + "/lightbox-plus-jquery.min.js")        ]).then(()=>{            this.lightboxLoaded = true;        });        }}

I'm using it for a B2B record page.

I can see that the third-party library and the css file are correctly loaded on the page by inspectioning the web page, but it seems like the web page ignored them. 

I've use the same HTML code in a local html file and it works, my guess is that Salesforce is blocking something.

 

Are there any suggestions?

Thank everybody

0/9000
2 answers
  1. Dec 1, 2024, 10:28 PM

    Using third-part JavaScript libraries may become difficult, particularly when those libraries will inject <script /> or <style /> tags in the DOM at the document level (LWS will block this), requiring rework of any components depending on these libraries to accommodate LWS.

0/9000