Play Games

Search This Blog

Tuesday, May 25, 2021

Get recordId in the lwc component - Salesforce Globe For You

 Get recordId in the lwc component  - Salesforce Globe For You 

Solution: Use the recordId property in the lwc javascript file.

When this component is used on the lightning record page,the page automatically sets the recordId property with the ID of the current record.

Example:

displayRecordIdInLwc.html

<template>

    <lightning-card>

        <div style="padding-left: 10px;"><strong>Record Id :</strong>{recordId}</div>

    </lightning-card>

</template>

displayRecordIdInLwc.js

import { LightningElement,api } from 'lwc';

export default class DisplayRecordIdInLwc extends LightningElement {

    @api recordId;

}

displayRecordIdInLwc.js-meta.xml

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

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

    <apiVersion>51.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



How to identify which salesforce edition you are using - Salesforce Globe For You

 How to identify which salesforce edition you are using  - Salesforce Globe For You 

Solution: In the company information,next to Organization Edition field,you can find which salesforce edition it is.

Login to the salesforce org --> setup --> company settings --> click on Company Information

You will be able to see the salesforce edition as shown in the image below.



Monday, May 17, 2021

display popup/modal on button click in lightning salesforce - Salesforce Globe For You

 display popup/modal on button click in lightning salesforce  - Salesforce Globe For You 

displayPopup.html

<template>

    <lightning-card  title="Popup Example">

    <div class="slds-p-around_medium">

        <lightning-button label="Open Popup" variant="brand" onclick={openPopupModal}>

        </lightning-button>

        <template if:true={openPopup}>

            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">

                <div class="slds-modal__container">

                <header class="slds-modal__header">

                <button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close" onclick={closePopupModal}>

                <lightning-icon icon-name="utility:close" size="medium"> 

                </lightning-icon> 

                <span class="slds-assistive-text">Close</span>

                </button>

                <h2 id="modal-heading-01" class="slds-modal__title slds-hyphenate">Header</h2>

                </header>

                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">

                <p> Body</p>

                </div>

                <footer class="slds-modal__footer">

                <button class="slds-button slds-button_neutral" onclick={closePopupModal}>Cancel</button>

                <button class="slds-button slds-button_brand">Save</button>

                </footer>

                </div>

                </section>

                <div class="slds-backdrop slds-backdrop_open"></div>

            </template>

    </div>

</lightning-card>

</template>

displayPopup.js

import { LightningElement,api } from 'lwc';

export default class DisplayPopup extends LightningElement {

    @api openPopup = false;

    openPopupModal(){

        this.openPopup = true;

    }

    closePopupModal() {

        this.openPopup = false;

    }

}

displayPopup.js-meta.xml

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

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

    <apiVersion>51.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



fetch picklist field values in lightning salesforce - Salesforce Globe For You

 fetch picklist field values in lightning salesforce  - Salesforce Globe For You 

In this example,  the LeadSource picklist field values of Lead object are fetched and displayed in lwc component.

Example:

displayPicklistFieldValues.html

<template>

    <lightning-card  title="Display Lead Source Picklist Field Values">

        <p class="slds-p-horizontal_small">

            <lightning-combobox

            name="Lead Source"

            label="Lead Source"

            value={selectedPicklistValue}

            placeholder="Select Lead Source"

            options={leadSourcePicklistValues}

            onchange={handlePicklistChange} ></lightning-combobox>

        </p>

        <p>Selected Picklist Value is:{selectedPicklistValue}</p>

    </lightning-card>

</template>

displayPicklistFieldValues.js

import { LightningElement,wire,api,track} from 'lwc';

import { getPicklistValues } from 'lightning/uiObjectInfoApi';

import { getObjectInfo } from 'lightning/uiObjectInfoApi';

import LEAD_OBJECT from '@salesforce/schema/Lead';

import LEADSOURCE_FIELD from '@salesforce/schema/Lead.LeadSource';

export default class DisplayPicklistFieldValues extends LightningElement {

    @api leadSourcePicklistValues;

    @track selectedPicklistValue;

    @wire(getObjectInfo, { objectApiName:LEAD_OBJECT  }) leadObjectMetaData;

    @wire(getPicklistValues, { recordTypeId: '$leadObjectMetaData.data.defaultRecordTypeId', fieldApiName: LEADSOURCE_FIELD })

    fetchPiclistValue({data,error}){

        if(data) {

            this.leadSourcePicklistValues = data.values;

        } 

        if(error) {

            console.log(error);

        }

    }

    handlePicklistChange(evt) {

        this.selectedPicklistValue = evt.detail.value;

    }

}

displayPicklistFieldValues.js-meta.xml

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

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

    <apiVersion>51.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



Wednesday, May 12, 2021

Get the current apex context at run time salesforce - Salesforce Globe For You

 Get the current apex context at run time salesforce  - Salesforce Globe For You 

Solution: Use the getCurrent(),getQuiddity() and getRequestId() methods of Request class to know the currrent apex context.

getQuiddity() returns a value such as ANONYMOUS or BATCH_APEX or FUTURE based on context.

Example: Run below code from Execute Anonymous window

Request objRequest = Request.getCurrent();

Quiddity objQuiddity = objRequest.getQuiddity();

system.debug('Quiddity'+objQuiddity);

The debug returns ANONYMOUS as the current context is Execute Anonymous window.

Output:


Use Aura component in Quick Action Salesforce - Salesforce Globe For You

 Use Aura component in Quick Action Salesforce  - Salesforce Globe For You 

Solution: In order to use aura component in quick action,the component should implement force:lightningQuickAction interface.

Example:

<aura:component implements="force:lightningQuickAction">

    This is the Aura Component for Quick Action

</aura:component>

Note: Add the button in the respective pagelayout in order to appear.





Saturday, May 1, 2021

covert 18 digit salesforce record Id to 15 digits - Salesforce Globe For You

 covert 18 digit salesforce record Id to 15 digits  - Salesforce Globe For You 

Solution: use to15() to do this.

code:

Id lead18DigitId = '00Q0o00001fxEZiEAM'; // keep 18 digit id

string lead15DigitId = lead18DigitId.to15();

system.debug('Lead 15 digit Id : '+lead15DigitId);

get the logged in user email in apex salesforce - Salesforce Globe For You

 get the logged in user email in apex salesforce  - Salesforce Globe For You 

Solution: Use UserInfo.getUserEmail() to get the logged in user email.

Code

String strLoggedInUserEmail = UserInfo.getUserEmail();

system.debug('Logged in User Email: '+strLoggedInUserEmail);


How to know the user who created or modified the Aura component salesforce - Salesforce Globe For You

 How to know the user who created or modified the Aura component salesforce  - Salesforce Globe For You 

Solution: Use SOQL Query below

SELECT Id, DeveloperName, CreatedBy.Name, LastModifiedBy.Name,CreatedDate, LastModifiedDate FROM AuraDefinitionBundle where DeveloperName ='MultipleTabs' 

where MultipleTabs is the name of the component.



Output:



Note: Keep the tooling API checkbox to true in developer console while executing the query.

How to know the user who created or modified the Lightning component salesforce

 How to know the user who created or modified the Lightning component salesforce

Solution: Use SOQL Query below

SELECT Id, DeveloperName, CreatedBy.Name, LastModifiedBy.Name,CreatedDate, LastModifiedDate FROM LightningComponentBundle where DeveloperName ='dynamicTabsInLWC' 

where dynamicTabsInLWC is the name of the component.



Output:



Note: Keep the tooling API checkbox to true in developer console while executing the query.