I'm a LWC noob and am trying to figure out how to create a LWC that allows the user to select a campaign record and then uses that values from that record to create fundraising thermometer visualization available on community/digital experience pages.
I was able to hard code the campaign Id to get the values I needed, but would like to make it so that users can select one of many records that meet the criteria.( see picture for example of the functionality I'm trying to recreate.
Thanks for any help!
Here is the code I was messing around with to just get the data not formatting it as a thermometer.
JS file
import { LightningElement, track, wire } from 'lwc';
import getCampaigns from '@salesforce/apex/testCampaign.getCampaigns'
export default class Totalraised extends LightningElement {
@track columns = [
{label:'Name', fieldName: 'Name'},
{label: 'Total Amount Raised', fieldName: 'AmountWonOpportunities'}
];
@track campaignList;
@wire(getCampaigns) wireCampaigns({data,error}){
if (data) {
this.campaignList = data;
console.log(data);
} else if (error) {
console.log(error);
}
}
}
HTML FILE
<template>
<div style="height: 500px;">
<template if:true={campaignList}>
<lightning-datatable
key-field="id"
data={campaignList}
columns={columns} >
</lightning-datatable>
</template>
</div>
APEX CLASS REFERENCED
public with sharing class testCampaign {
@AuraEnabled(cacheable=true)
public static List<Campaign> getCampaigns() {
return [SELECT Id, Name, AmountWonOpportunities FROM Campaign WHERE Id = '7017c000002FfgAAAS'];}}
Best Answer
Hello Thomas and welcome to Salesforce StackExchange.
This is a more advanced topic but it is possible through Dynamic Picklists.
You will have to configure the component to expose a property for the selected Campaign (e.g.
selectedCampaignId
), then on meta XML something like:And then on
MyCampaigns
you retrieve the options:Reference on how to configure components for usage in Digital Experience (previously known as Community): Configure a Component for Experience Builder.
Reference for Dynamic Picklist.