Play Games

Search This Blog

Monday, April 22, 2024

How to access custom labels in lightning web component salesforce - Salesforce Globe 4u

 Solution: 

Step1: Import the label in LWC using the below import 

import labelname from "@salesforce/label/labelreference";

Step2: create label object as below 

label ={

        myblogURL

    }

Reference the custom label in html file using label.labelname.

Example:



customLabelInLWC.html:

<template>

    <lightning-card>

        <h1> Custom Label value :{label.myblogURL}</h1>

    </lightning-card>

</template>

customLabelInLWC.js:

import { LightningElement } from 'lwc';

import myblogURL from "@salesforce/label/c.Blog_URL";

export default class CustomLabelInLWC extends LightningElement {

    label ={

        myblogURL

    }

}

customLabelInLWC.js-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <apiVersion>59.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



Notes related list is missing in record detail page to capture notes in salesforce - Salesforce Globe 4u

Solution: Need to enable notes feature in order to add notes related list

Step1: we need to enable notes feature first.

Go to setup --> Feature Settings --> Sales --> Notes Settings --> enable the 'Enable Notes' checkbox.

Step 2: Add the Notes related list to the respective page layout 

That's it. You will be able to see Notes related list to add new notes.




Enjoy learning salesforce.

How to get the count of number of custom objects in salesforce org - Salesforce Globe 4u

There are 2 ways to know this.

Solution1: Login into the org and Go to the setup --> System Overview.

Here you will find the required details.

Solution2: Run the piece of code in execute anonymous windows of Developer console

Map<String, SObjectType> sObjects = Schema.getGlobalDescribe();

Integer noOfCustomObjects = 0;

for (SObjectType obj : sObjects.values())

{

    if(obj.getDescribe().isCustom() == true) {

        noOfCustomObjects = noOfCustomObjects+1;

        //system.debug(obj.getDescribe().getName());

    }

}

System.debug('Number of Custom Objects: '+noOfCustomObjects);

Output:



Saturday, April 20, 2024

Lightning Messaging Service example in salesforcelightning web component

 Lightning Messaging Service: It is used to communicate between the visualforce pages, aura components and Lightning web Components. It can be used to communicate between one aura component and one Lightning web component as well and also between one visualforce page and one aura component as well.

Example: In this example you can see how a message is communicated from one lightning web component to other lightning web component
Step 1: Create a lightning messaging channel: Go to visual studio code tool and create 'messageChannels' folder inside the default folder as shown in image below


create a file as 'filename.messageChannel-meta.xml' shown in the image below and deploy to salesforce org.




Step 2: Create publisher lightning web component(source)
publisherLWCComponent.html:
<template>
<lightning-card>
<div class="slds-grid">
<lightning-button label="Publish" variant="brand" onclick={sendMessage}></lightning-button>
</div>
</lightning-card>
</template>

publisherLWCComponent.js:
import { LightningElement } from 'lwc';
import { createMessageContext, releaseMessageContext,publish} from 'lightning/messageService';
import msg from "@salesforce/messageChannel/TestMessageChannel__c";
export default class PublisherLWCComponent extends LightningElement {
context = createMessageContext();
sendMessage() {
const msgTosend = {
paramOne: 'This is message to be sent to other LWC'
}
publish(this.context, msg, msgTosend);
};
}

publisherLWCComponent.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>

Step3: Create Subscriber Lightning web component(destimation):
subscriberLWCComponent.html:
<template>
<lightning-card>
Message Received: {msgReceived}
</lightning-card>
</template>

subscriberLWCComponent.js:
import { LightningElement,track } from 'lwc';
import { createMessageContext, releaseMessageContext,APPLICATION_SCOPE,subscribe, unsubscribe } from 'lightning/messageService';
import msg from "@salesforce/messageChannel/TestMessageChannel__c";
export default class SubscriberLWCComponent extends LightningElement {
context = createMessageContext();
@track msgReceived ='';
connectedCallback(){
subscribe(this.context, msg, (message) => {
this.msgReceived = message.paramOne;
},{scope: APPLICATION_SCOPE});

}
}
subscriberLWCComponent.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Output: