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.

#LWC Development2 discussing

Hello community , 

 

I have 2 components - componentA(parent) and component B(child) 

 

when I pass data from parent to child , data is not visible. 

 

can anyone explain why ? 

 

component A html - 

 

<template>

    <lightning-card label="component A - parent">

        <p>Hi.I am component A.Parent</p>

        <c-component-B>

            {property1}="hi.I am component B.child component"

            {property2}="Welcome"

        </c-component-B>

    </lightning-card>

</template>   

 

component A js - 

 

import { LightningElement } from 'lwc';

 

export default class ComponentA extends LightningElement {

   

 

component B html - 

 

<template>

    <lightning-card>

       <p>message passed from {property1}</p>

       <p>message passed from {property2}</p>

    </lightning-card>

</template> 

 

component B js - 

 

import { LightningElement,api} from 'lwc';

 

export default class ComponentB extends LightningElement {

 

    @api property1;

    @api property2;

 

 

can anyone suggest something ?? 

 

#Developer Forums  #Trailhead Challenges  #Trailhead  #Data Management  #LWC  #LWC Development  #Sales Cloud  #Salesforce Developer  #Salesforce Admin

1 answer
  1. Today, 12:35 AM

     In LWC, to pass data from a parent to a child, you use the @api decorated properties in the child component and bind them using standard HTML attribute syntax

    (e.g., property1="value"), not the curly brace notation you’ve used. The curly braces {} are used for expressions or data binding within the same component, not for passing props directly. 

     

    component A html - 

     

    <template>    <lightning-card label="Component A - Parent">        <p>Hi. I am Component A. Parent</p>        <c-component-b property1="Hi. I am Component B. Child component" property2="Welcome"></c-component-b>    </lightning-card></template>
0/9000

Hi All,

I want to learn the LWC in Salesforce.

Could anyone please provide the roadmap that I need to follow.

If possible could please share the resources as well

Thanks in advance 😇

#Salesforce Developer #LWC #LWC Component #LWC Development #LWC Components
11 answers
  1. Oct 25, 2024, 9:57 AM

    I can share you my udemy credentials..

    you can learn lwc from there as well or from the resources above provided

0/9000

Hi,

I am trying to reload the previous page after saving an edit form. After clicking on Save, I have used  window.history.back(); but it only navigates to the previous page, I require it to reload as well. Is there a way to do this?

#LWC  #LWC Component #Custom LWC #LWC Development #LWC Components

4 answers
  1. Dec 10, 2024, 7:23 AM

    Hii,

    To navigate back and reload the previous page, the most straightforward solution is to use window.history.back() followed by a short delay and window.location.reload().

     

    The implementation may look something like this : 

    window.history.back();

    setTimeout(function() {

    window.location.reload();

    }, 500);

0/9000

//I have created checkboxes using checkgroup the checkboxes are in single line iam trying to align in two columns but iam not succeded.  

<lightning-checkbox-group name="Checkbox Group" label="Checkbox Group" options={options}                         value={value} onchange={handleChange}></lightning-checkbox-group>                     <p>Selected Values are: {selectedValues}</p>

 

Thanks for any Help

 

#Trailhead #LWC #LWC Development #LWC Component #Lightning #Lightning Web Components

2 answers
  1. Nov 18, 2024, 3:01 PM

    To display checkboxes in two columns using lightning-checkbox-group, you'll need to adjust the layout using CSS because lightning-checkbox-group doesn't natively support multi-column layouts out of the box.

     

    You can achieve the two-column layout by wrapping the checkboxes in a custom div container and using CSS Grid or Flexbox to display the checkboxes in two columns.

     

    You can use something like this : 

    /* Styling for the checkbox container to use grid */

    .checkbox-container {

     display: grid; /* Use grid layout */

     grid-template-columns: repeat(2, 1fr); /* Create two equal columns */

     gap: 16px; /* Add space between checkboxes */

     max-width: 600px; /* Optional: set a max width */

    }

     

    /* Ensure the checkbox options fit well inside each column */

    .lightning-checkbox-group .slds-checkbox_faux {

     margin-bottom: 8px; /* Adjust the spacing between checkboxes */

    }

0/9000

Hi all

I have written LWC that adds a new row whenever I click on the plus button but the newly added row inherits the value from the previous row. I want to set the values for the newly created rows as optional. Can anyone please help me here?

 

New Row inherits the value of previous row

 

#LWC Component  #LWC Development  #LWC

3 answers
  1. Oct 10, 2024, 8:26 AM

    Hii,

    If you want to ensure that newly added rows do not inherit values from the previous row, you should make sure that the data structure you use to hold the rows is initialized with completely new values each time(ideally blank here).

    You can use row add approach something like this 

     

    // The new row that you create, make its value empty

    const newRow = { id: rowId++, field1: '', field2: '' }

    OR 

    if you are fetching existing value, make sure to make it empty before adding the row.

     

    With this implementation, clicking the "Add Row" button will create a new row with empty fields, preventing any inheritance of values from previous rows. This way, all fields in newly created rows remain optional until filled by the user.

    If this does not work, please share exact context with more information.

     

    Please mark this as best answer if it solved your query.

0/9000

@api recordId is not loading immediately in LWC used in QuickAction when 

 

  1. Initially clicked on quick action => recordId - works Fine 
  2. Updated record without reloading the page (which is done by another LWC in record Page)
  3. Again clicked on quick action => recordId - Will not load for immediate click so need to get from url 

 

#LWC  #LWC Development

1 comment
  1. Oct 9, 2024, 9:30 AM

    If you're updating records via another LWC and need to refresh data in the Quick Action component, consider using refreshApex to re-fetch the record information.

    RefreshApex is useful for ensuring that your Lightning Web Component (LWC) reflects the most current data, especially after a record update. It is a utility that allows you to refresh data fetched using @wire. It updates the record information without requiring a full page reload.

     

    Ensure that the data you retrieve is done using the @wire decorator; this is necessary for refreshApex to function properly.

     

    For detailed info on refreshApex , you can go through :

    https://developer.salesforce.com/docs/platform/lwc/guide/apex-result-caching.html

0/9000

lightning-input for number should show a step indicator to increase/decrease the number. This is not showing, but the HTML input element shows that. 

 

Lightning-input

<lightning-input type="number" data-id={product.ProductId} value="1" label="" min="1" max="99" step="1"></lightning-input>step is not showing for lightning-input for numberHTML Input

<input type="number" data-id={product.ProductId} value="1" min="1" max="99"></input>html-input.pngIs something wrong with my code? or issue with the lightning-input element?

 

#LWC #LWC Development #LWC Components

5 answers
0/9000

Resources from the Salesforce Developers Ask Me Anything on The Future of Lightning Web Components

 

I hope you joined us for the fantastic #SFDevsAMA on Wednesday 28th February 2024 featuring @Danielle Larregui and @Greg Whitworth. They loved answering your questions about The Future of Lightning Web Components. If you missed it, don't worry - we recorded the series and our experts have provided some great resources that our experts for you to continue your learning! 

#Ask An Expert #SFDevsAMA #CommUpdates #LWC #Lightning Web Components #LWC Development

3 comments
0/9000

Hi Guys,

Can you please suggest how can we print pdf from lwc component?

I tried window.print() which gives whole page, we only want contents from our lwc component. 

 

#LWC Development

#Download Pdf

6 answers
  1. Jul 17, 2024, 12:38 PM

    Hello community! 

    I had similar task and was able to complete it using just lwc! 

     

    For that I had to create the following js method:

     

    handlePrintClick () {

    let printableElement = this.template.querySelector('.print-section');

    if (printableElement) {

    let clone = printableElement.cloneNode(true);

    let printWindow = window.open('', '_blank');

    if (printWindow) {

    printWindow.document.body.appendChild(clone);

    let style = printWindow.document.createElement('style');

    style.textContent = `

    @page {

    size: auto; /* auto is the initial value */

    margin: 0mm; /* this affects the margin in the printer settings */

    }

    @media print {

    body {

    margin: 0;

    padding: 0;

    }

    .no-print {

    display: none;

    }

    }

    `;

    printWindow.document.head.appendChild(style);

    printWindow.focus();

    printWindow.print();

    printWindow.close();

    } else {

    console.error('Failed to open print window');

    }

    } else {

    console.error('Printable element not found');

    }

    }

    and you need to update the content of html with css class to the place which you wanted to print (I had lots of inner data, parent and childs)

     

    <div class="print-section">

    Data which should be printed

    </div>

    Note: In my case I had all css values in the same html file (not a separate css, I used style tag) 

0/9000