LWC: customer360RelatedContacts: JavaScript
Tue Jan 16 2024 10:34:28 GMT+0000 (Coordinated Universal Time)
Saved by @FloLiman
import { LightningElement, api, wire } from 'lwc'; import { NavigationMixin } from 'lightning/navigation'; import getCaseAccountContact from '@salesforce/apex/customer360CommunicationsHelper.getCaseAccountContact'; //Columns to show the Account Name and the Alternative Billing Name const columns = [ { label: 'Account Name', fieldName: 'AccountId', type: 'url', typeAttributes: { label: { fieldName: 'AccountName' }, target: '_self' } }, { label: 'Alternative Billing Name', fieldName: 'AlternativeBillingName', type: 'url', typeAttributes: { label: { fieldName: 'ContactAlternativeBillingName' }, target: '_self' } }, ]; //URL variables const ACCOUNT_URL = '/lightning/r/Account/'; const CONTACT_URL = '/lightning/r/Contact/'; const VIEW_URL = '/view'; export default class Customer360Communications extends NavigationMixin(LightningElement) { columns = columns; @api recordId; contact; //Text Variables contactPreferencesFormatText = 'Communications format - '; contactPreferencesText = 'Communication preference - '; marketingConsentText = 'Marketing consent - '; @wire(getCaseAccountContact, { caseId: '$recordId' }) wiredData({ error, data }) { if (data) { this.caseAccountContactData = data.map(contact => ({ ...contact, AccountId: contact.AccountId ? ACCOUNT_URL + contact.AccountId + VIEW_URL : '', AlternativeBillingName: contact.ContactAlternativeBillingName ? CONTACT_URL + contact.ContactId + VIEW_URL : '', strContactURL: CONTACT_URL + contact.ContactId + VIEW_URL, strMarketingConsent: this.marketingConsentText + contact.ContactOpted, strContactPrefs: this.contactPreferencesText + contact.ContactPreferences, strCommsPrefFormat: this.contactPreferencesFormatText + contact.PreferredCommunicationFormat })); this.contact = this.caseAccountContactData[0]; } else if (error) { console.error('Error fetching data:', error); } } }
Comments