Play Games

Search This Blog

Tuesday, August 10, 2021

How to retrieve remote site settings using package.xml in visual studio code - Salesforce Globe For You

 How to retrieve remote site settings using package.xml in visual studio code  - Salesforce Globe For You 

Solution :use the below package.xml

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

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

    <types>

        <members>*</members>

        <name>RemotesiteSetting</name>

    </types>

    <version>52.0</version>

</Package>

Output:



Saturday, August 7, 2021

How to remove border around icon in lightning web component(LWC) - Salesforce Globe For You

How to remove border around icon in lightning web component(LWC)  - Salesforce Globe For You 

Solution: use variant="bare" for <lightning-button-icon> tag

Example:

removeBorderIconLWC.html

<template>

    <lightning-card title="Remvoing Border around Delete Icon in LWC">

        <lightning-button-icon icon-name="utility:delete" alternative-text="Delete" class="test slds-m-left_xx-small" 

        variant="bare" title="Delete"></lightning-button-icon>

    </lightning-card>

</template>

removeBorderIconLWC.js

import { LightningElement } from 'lwc';

export default class RemoveBorderIconLWC extends LightningElement {}

removeBorderIconLWC.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 hide label of lightning combobox or drop down in lightning web component(LWC) - Salesforce Globe For You

 How to hide label of lightning combobox or drop down  in lightning web component(LWC)  - Salesforce Globe For You 

Solution: Use variant="label-hidden" or remove label="".if we remove label ,you can still find empty space for label.

hideLabelLightningInputLWC.html

<template>

    <lightning-card title="Hide Label of Combobox">

        Industry Drop Down with Label <br/><br/><br/>

        <template if:true={industryPicklist.data}>

        <lightning-combobox name="Industry"  value={Industry} label="Industry"

            options={industryPicklist.data.values}>

        </lightning-combobox>

        </template>

        Industry Drop Down without  Label <br/><br/><br/>

        <template if:true={industryPicklist.data}>

            <lightning-combobox name="Industry"  value={Industry} label="Industry"

                options={industryPicklist.data.values} variant="label-hidden">

            </lightning-combobox>

        </template>

        Industry Drop Down without  Label <br/><br/><br/>

        <template if:true={industryPicklist.data}>

            <lightning-combobox name="Industry"  value={Industry}

                options={industryPicklist.data.values} >

            </lightning-combobox>

        </template>

    </lightning-card>

</template>

hideLabelLightningInputLWC.js

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

import { getObjectInfo } from 'lightning/uiObjectInfoApi';

import { getPicklistValues } from 'lightning/uiObjectInfoApi';

import ACCOUNT_OBJECT from '@salesforce/schema/Account';

import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';

export default class HideLabelLightningInputLWC extends LightningElement {

    @api industry;

    @track lstAccount = [];

    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT }) accountMetaData;

    @wire(getPicklistValues,{

            recordTypeId: '$accountMetaData.data.defaultRecordTypeId', 

            fieldApiName: INDUSTRY_FIELD

        }

    ) industryPicklist;

}

hideLabelLightningInputLWC.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:



Add Row funnctionality in Lightning webcomponent- Salesforce Globe For You

 Add Row funnctionality in LWC Salesforce - Salesforce Globe For You

ApexClass:

public class AddRowController {

    @AuraEnabled

    public static List<AccountWrapper> fetchAccounts() {

        List<AccountWrapper> lstAccountWrapper = new List<AccountWrapper>();

        for(Account objAccount:[Select id,name,Industry from Account limit 2]) {

            AccountWrapper objAccountWrap = new AccountWrapper();

            objAccountWrap.AccountId = objAccount.Id;

            objAccountWrap.AccountName = objAccount.Name;

            objAccountWrap.Industry = objAccount.Industry;

            objAccountWrap.Del = false;

            lstAccountWrapper.add(objAccountWrap);

        }

        return lstAccountWrapper;

 }

    @AuraEnabled

    public static List<AccountWrapper> saveAccounts(List<AccountWrapper> lstAccountWrap) {

        List<AccountWrapper> lstAccountWrapper = new List<AccountWrapper>();

        List<Account> lstAccount = new List<Account>();

        List<Account> lstAccountToDel = new List<Account>();

        for(AccountWrapper objAccountWrap :lstAccountWrap) {

            Account objAccount = new Account();

            if(objAccountWrap.Del && objAccountWrap.AccountId != null) {

                objAccount.Id = objAccountWrap.AccountId;

                lstAccountToDel.add(objAccount);

            } else {

                objAccount.Id = objAccountWrap.AccountId;

                objAccount.Name = objAccountWrap.AccountName;

                objAccount.Industry = objAccountWrap.Industry;

                lstAccount.add(objAccount);

            }

        }

        if(!lstAccountToDel.isEMPTY()) {

            Delete lstAccountToDel;

        }

        List<Database.upsertResult> result = Database.upsert(lstAccount,false);

        for(Account objAccount:[Select id,name,Industry from Account where id in:lstAccount]) {

            AccountWrapper objAccountWrap = new AccountWrapper();

            objAccountWrap.AccountId = objAccount.Id;

            objAccountWrap.AccountName = objAccount.Name;

            objAccountWrap.Industry = objAccount.Industry;

            objAccountWrap.Del = false;

            lstAccountWrapper.add(objAccountWrap);

        }

        return lstAccountWrapper;

    }

    public with sharing class AccountWrapper {

        @AuraEnabled public String AccountName {set;get;}

        @AuraEnabled public String AccountId {set;get;}

        @AuraEnabled public String Industry {set;get;}

        @AuraEnabled public boolean Del {set;get;}

    }

}

addRowLWC.html

<template>

    <lightning-card title="Add Row Functionality">

        <table class="slds-table slds-table_cell-buffer slds-table_bordered">

            <thead>

                <tr >

                    <th  class="slds-is-resizable" scope="col">

                        <div>

                            Account Name

                        </div>

                    </th>

                    <th  class="slds-is-resizable" scope="col">

                        <div>

                            Industry

                        </div>

                    </th>

                    <th >

                        <lightning-button-icon icon-name="utility:info"    alternative-text="Info"   class="slds-m-left_xx-small" title="Info" variant="bare"></lightning-button-icon>

                    </th>

                </tr>

            </thead>

            <tbody>

                <template if:true={lstAccount}>

                    <template for:each={lstAccount} for:item="objAccount" for:index="index">

                        <tr key={objAccount.AccountId} if:false={objAccount.Del}>

                            <th>

                                <lightning-input type="text" class="slds-truncate" data-id={index} title={objAccount.AccountName} value={objAccount.AccountName} variant="label-hidden" onchange={nameChange}></lightning-input>

                            </th>

                            <th>

                                <template if:true={industryPicklist.data}>

                                    <lightning-combobox name="Industry"  value={objAccount.Industry}

                                    data-id={index} options={industryPicklist.data.values} onchange={industryChange} variant="label-hidden">

                                    </lightning-combobox>

                                </template>

                            </th>

                            <th >

                                <lightning-button-icon data-id={index} icon-name="utility:delete"    alternative-text="Delete"   class="test slds-m-left_xx-small" title="Delete" variant="bare" onclick={deleteRow}></lightning-button-icon>

                            </th>

                        </tr>

                    </template>

                </template>

            </tbody>

        </table>

        <div>

            <lightning-button variant="brand" label="Add Row" title="Add Row" onclick={addRow} class="slds-m-left_x-small"></lightning-button>

            <lightning-button variant="brand" label="Save Accounts" title="Save Accounts" onclick={saveAccountData} class="slds-m-left_x-small"></lightning-button>

        </div> 

    </lightning-card>

</template>

addRowLWC.html.js

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

import { getObjectInfo } from 'lightning/uiObjectInfoApi';

import { getPicklistValues } from 'lightning/uiObjectInfoApi';

import ACCOUNT_OBJECT from '@salesforce/schema/Account';

import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';

import fetchAccounts from '@salesforce/apex/AddRowController.fetchAccounts';

import saveAccounts from '@salesforce/apex/AddRowController.saveAccounts';

export default class AddRowLWC extends LightningElement {

    @api recordId;

    @track lstAccount = [];

    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT }) accountMetaData;

    @wire(getPicklistValues,{

            recordTypeId: '$accountMetaData.data.defaultRecordTypeId', 

            fieldApiName: INDUSTRY_FIELD

        }

    ) industryPicklist;

    connectedCallback() {

        fetchAccounts()

        .then(result => {

            if(result){

                this.lstAccount = result;

            }

        })

        .catch(error => {

            this.loader = false;

            this.error = error;

        });

    }

    addRow(event){

        let newRecord ={AccountId:null,AccountName:null,Del:false};

        this.lstAccount.push(newRecord);

    }

    deleteRow(event) {

        var selectedRow = event.currentTarget;

        var key = selectedRow.dataset.id;

        this.lstAccount[key].Del = true;

    }

    saveAccountData(event){

        saveAccounts({lstAccountWrap:this.lstAccount})

        .then(result => {

            if(result){

                this.lstAccount = result;

            }

        })

        .catch(error => {

            this.loader = false;

            this.error = error;

        });

    }

    nameChange(event){

        var selectedRow = event.currentTarget;

        var key = selectedRow.dataset.id;

        this.lstAccount[key].AccountName = event.detail.value;

    }

    industryChange(event) {

        var selectedRow = event.currentTarget;

        var key = selectedRow.dataset.id;

        this.lstAccount[key].Industry = event.detail.value;

        

    }

}

addRowLWC.html.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 get objectName from record Id in apex salesforce - Salesforce Globe For You

 How to get objectName from record Id in apex salesforce  - Salesforce Globe For You 

Solution:

Id recordId = '00Q0o00001fxEZiEAM';

Schema.SObjectType sobjectType = recordId.getSObjectType();

String sobjectName = sobjectType.getDescribe().getName();

system.debug('Object Name : '+sobjectName);

Output:




How to show delete icon in lightning web component(LWC) - Salesforce Globe For You

 How to show delete icon in lightning web component(LWC)  - Salesforce Globe For You 

Solution: use <lightning-button-icon icon-name="utility:delete"    alternative-text="Delete"   class="test slds-m-left_xx-small" title="Delete"></lightning-button-icon>

deleteIconLWC.html

<template>

    <lightning-card title="Delete Icon in LWC">

        <lightning-button-icon icon-name="utility:delete"    alternative-text="Delete"   class="test slds-m-left_xx-small" title="Delete"></lightning-button-icon>

    </lightning-card>

</template>

deleteIconLWC.js

import { LightningElement } from 'lwc';

export default class DeleteIconLWC extends LightningElement {

}

deleteIconLWC.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: