You need to sign in to do that
Don't have an account?
Mike Tol 1
A simple concatenation question
Hi everyone!
I have contact table and need to get Id + Name as concatenation of Id '0032v000034aSJyAAM' and string 'Name' like on the image.
Please tell me how can I do that.
Here is code:
Html:
<template>
<lightning-card title="Contacts">
<lightning-layout multiple-rows="true" vertical-align="end">
<lightning-layout-item size="12" padding="around-small">
<lightning-datatable key-field="id" data={contacts} columns={columns}></lightning-datatable>
</lightning-layout-item>
</lightning-layout>
</lightning-card>
</template>
Js:
import { LightningElement , wire} from 'lwc';
import getContacts from '@salesforce/apex/Qqq.getContacts';
let N = 'Name';
const columns = [
{ label: 'idName', fieldName: 'Id' + N, type: 'text' },
{ label: 'Name', fieldName: 'recordLink', type: 'url',
typeAttributes: {label: {fieldName: "ContactName"}, tooltip: "Name", linkify: true} }
];
export default class ContactTable extends LightningElement {
columns = columns;
contacts;
@wire(getContacts)
wiredContacts(value) {
const {error, data} = value;
if (data) {
let contactData = JSON.parse(JSON.stringify(data));
contactData.forEach(record => {
record.recordLink = "/" + record.Id;
record.ContactName = record.Name;
});
this.contacts = contactData;
} else if (error) {
this.error = error;
}
}
}
Apex:
public with sharing class Qqq {
@AuraEnabled(cacheable=true)
public static List<Lead> getLeads() {
List<Lead> leads = [
SELECT Id, Name, Title, Phone
FROM Lead
WHERE Name Like 'Lisa%'
Limit 3
];
System.debug('leads = ' + leads);
return leads;
}
@AuraEnabled(cacheable=true)
public static List<Contact> getContacts() {
List<Contact> contacts = [
SELECT Id, Name
FROM Contact
//WHERE LastName Like 'Apex%'
Limit 3
];
System.debug('contacts = ' + contacts);
return contacts;
}
}
I have contact table and need to get Id + Name as concatenation of Id '0032v000034aSJyAAM' and string 'Name' like on the image.
Please tell me how can I do that.
Here is code:
Html:
<template>
<lightning-card title="Contacts">
<lightning-layout multiple-rows="true" vertical-align="end">
<lightning-layout-item size="12" padding="around-small">
<lightning-datatable key-field="id" data={contacts} columns={columns}></lightning-datatable>
</lightning-layout-item>
</lightning-layout>
</lightning-card>
</template>
Js:
import { LightningElement , wire} from 'lwc';
import getContacts from '@salesforce/apex/Qqq.getContacts';
let N = 'Name';
const columns = [
{ label: 'idName', fieldName: 'Id' + N, type: 'text' },
{ label: 'Name', fieldName: 'recordLink', type: 'url',
typeAttributes: {label: {fieldName: "ContactName"}, tooltip: "Name", linkify: true} }
];
export default class ContactTable extends LightningElement {
columns = columns;
contacts;
@wire(getContacts)
wiredContacts(value) {
const {error, data} = value;
if (data) {
let contactData = JSON.parse(JSON.stringify(data));
contactData.forEach(record => {
record.recordLink = "/" + record.Id;
record.ContactName = record.Name;
});
this.contacts = contactData;
} else if (error) {
this.error = error;
}
}
}
Apex:
public with sharing class Qqq {
@AuraEnabled(cacheable=true)
public static List<Lead> getLeads() {
List<Lead> leads = [
SELECT Id, Name, Title, Phone
FROM Lead
WHERE Name Like 'Lisa%'
Limit 3
];
System.debug('leads = ' + leads);
return leads;
}
@AuraEnabled(cacheable=true)
public static List<Contact> getContacts() {
List<Contact> contacts = [
SELECT Id, Name
FROM Contact
//WHERE LastName Like 'Apex%'
Limit 3
];
System.debug('contacts = ' + contacts);
return contacts;
}
}
try below code.
don't forget to mark it as best answer.
Thank you
All Answers
Please below code:-
.JS
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
try below code.
don't forget to mark it as best answer.
Thank you
Thank you ravi!
I would be very grateful if you could more help me solve this problem:
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000Ucm9QAC