You need to sign in to do that
Don't have an account?

How to dynamically populate lightning checkbox group?
I’m trying to build a LWC that displays a checkbox group created from the list of active users in the same sales market as the current user.
Html file (based on component reference):
2) How do I take the results of my getCommissions Apex function and format it for the checkbox group value parameter?
Html file (based on component reference):
<template> <lightning-checkbox-group name="Checkbox Group" label="Select a User" options={comms} value={value} onchange={handleChange}> </lightning-checkbox-group> <p>Selected Values are: {selectedValues}</p> </template>js file:
import { LightningElement, api, track, wire } from "lwc"; import getMktUsers from "@salesforce/apex/Top100.getMktUsers"; import getCommissions from "@salesforce/apex/Top100.getCommissions"; import Id from "@salesforce/user/Id"; let url_string = window.location.href; let url = new URL(url_string); let rid = url.searchParams.get("Id"); export default class Top100 extends LightningElement { @api recordId; @api objectApiName; @api userId; @track value = ["Option1"]; userId = Id; recordId = rid; @wire(getMktUsers, { usrId: "$userId" }) MktUsers; @wire(getCommissions, { rid: "$recordId" }) selectedVals; objectApiName = "lda_Opportunity__c"; get comms() { return [{ label: "Ross", value: "Option1" }, { label: "Rachel", value: "Option2" }]; } get selectedValues() { return this.value.join(","); } handleChange(e) { this.value = e.detail.value; } }Apex file:
public with sharing class Top100 { @AuraEnabled(cacheable=true) public static List<Account> getMktUsers(Id usrId) { User ThisUser = [SELECT Id, Name, Office__c FROM User WHERE Id = :usrId LIMIT 1]; List<User> MarketUsers = [SELECT Id FROM User WHERE Office__c = :ThisUser.Office__c and IsActive = True]; //Users have matching Person accounts because some opportunities involve external sales people. return [SELECT Id, Name, FirstName, LastName FROM Account WHERE UserLookup__c IN :MarketUsers]; } @AuraEnabled(cacheable=true) public static List<String> getCommissions(Id rid){ List<String> values = new List<String>(); for (lda_Commission__c comm : [SELECT Agent__c, Agent__r.Name FROM lda_Commission__c WHERE DealId__c = :rid]){ values.add(comm.Agent__c); } System.debug('Values: ' + values); return values; } }1) How do I take the results of my Apex function and format it for the checkbox group options parameter?
2) How do I take the results of my getCommissions Apex function and format it for the checkbox group value parameter?
That could be easier with a function instead of a property for the wired parts.
myWiredMktUsers below is a free name for the function and it is automatically linked with the @wire annotation just above.
The function myWiredMktUsers has always a fixed object parameter with the error (result of the getMktUsers) and the returned data.
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.data_wire_service_about
In fact, you must convert mktUsers into "value" but I don't know your data. What do you see in the console log?
Chrome: Open the Console panel to view logged messages or run JavaScript
Press Command+Option+J (Mac) or Control+Shift+J (Windows, Linux, Chrome OS) to jump straight into the Consolepanel.
Did you put that in to the myWiredMktUsers function or into the get comms function or is that outside of either?
The only interesting thing is to get "error" maybe.
Otherwise, re-check the content of MktUsers (perhaps different).
I'm currently looping through the selected checkboxes and performing a createRecord and while it creates the records, none of the toasts display.