everyone! I'm a newbie in Salesforce, and I have a problem: I need to create datatable similar to that:
But the only one that I could do is that(I used a standard lightning-datatable
, also Usage Target field is a formula that concatenate records of two other fields):
Apex:
@AuraEnabled
public static List<UsageMetricWrapper> getUsageMetricRecords(){
List<UsageMetricWrapper> usageMetricListWrapper = new List<UsageMetricWrapper>();
List<Usage_Metric__c> usageMetricList = [SELECT Id, Name, Usage_Target__r.Used_Production_And_Licenses__c, Estimated_Last_Usage__c
FROM Usage_Metric__c];
if(!usageMetricList.isEmpty()){
for(Usage_Metric__c usageMetric : usageMetricList){
UsageMetricWrapper usageMetrciWrapper = new UsageMetricWrapper();
usageMetrciWrapper.Name = usageMetric.Name;
usageMetrciWrapper.ProductsAndLicenses = usageMetric.Usage_Target__r.Used_Production_And_Licenses__c;
usageMetrciWrapper.EstimatedLastUsage = usageMetric.Estimated_Last_Usage__c;
usageMetricListWrapper.add(usageMetrciWrapper);
}
}
return usageMetricListWrapper;
}
public class UsageMetricWrapper {
@AuraEnabled
public String Name{get;set;}
@AuraEnabled
public String ProductsAndLicenses{get;set;}
@AuraEnabled
public Date EstimatedLastUsage{get;set;}
}
JS:
import getUsageMetricRecords from '@salesforce/apex/LWCController.getUsageMetricRecords';
const columns = [
{ label: 'User', fieldName: 'UserName' },
{ label: 'Usage Metric: User Name', fieldName: 'Name' },
{ label: 'Usage Target', fieldName: 'ProductsAndLicenses' },
{ label: 'Estimated Last Usage', fieldName: 'EstimatedLastUsage' },
]
export default class Analysis extends LightningElement {
columns = columns;
records = [];
async connectedCallback() {
const allRecords = await getUsageMetricRecords();
this.records = allRecords;
}
HTML:
lightning-datatable key-field="Id"
data={records}
columns={columns}
Does anyone know, how to split text in a column so that it appears vertically and is separated by a line and also add the total number of "created" row data to the previous column? I will be grateful for any help!