Tuesday, 16 November 2021

How to get Object Translation and Custom Label Translations

 Hi,

Here we are going to learn how to retrieve Object Translations and Custom Label Translations.


Object Translations with Fields:


   <types>

                <members>Account-de</members>

                <members>Department__c_de</members>

               <name>CustomObjectTranslation</name>

    </types>

   <types>

                <members>Account.Status__c</members>

                <members>Department__c.Type__c</members>

               <name>CustomField</name>

    </types>

In the above we are trying to retrieve Object Translations for the German Language (de) for Account,Department__c with Fields Translations "Account.Status__c","Department__c.Type__c".


Custom Label Translation:

    <types>

      <members>*</members>

      <name>CustomLabels</name>

    </types>

     <types>

      <members>*</members>

      <name>Translations</name>

    </types>

Reference:
https://help.salesforce.com/s/articleView?id=sf.cl_translate_edit.htm&type=5
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_customobjecttranslation.htm
https://salesforce.stackexchange.com/questions/310123/retrieve-custom-translations-for-a-custom-label-via-the-metadata-api








Tuesday, 12 October 2021

Javascript filter() method

 Hi,

Here we are going to learn how to filter the objects in an array with filter() method.

  • The filter() method creates an array filled with all array elements that pass a test (provided by a function).
  • filter() does not execute the function for empty array elements.
  • filter() does not change the original array.


Example 1:

Prepare an array with words which has a length greater than 3 from the following arrray.

let words = ['elephant', 'cat', 'dog', 'tiger', 'lion'];

Without Filter method:

let wordsarray = [];

for (let i = 0; i < words.length; i++) {

    if (words[i].length> 3) {

        wordsarray.push(words[i]);

    }

}

console.log(wordsarray);

Output:

["elephant", "tiger", "lion"]


With filter method:

let wordsarray = [];

wordsarray  = words.filter(word => word.length > 3);

console.log(wordsarray );

Output:

["elephant", "tiger", "lion"]


Example 2:

 Find the cities whose population is greater than 30000 from the following array.

let cities = [

    {name: 'Hyderabad', population: 40000},

    {name: 'Karnool', population: 36000},

    {name: 'Kadapa', population: 37000},

    {name: 'Tirupati', population: 29000}  

];

Without Filter method:

let bigCities = [];

for (let i = 0; i < cities.length; i++) {

    if (cities[i].population > 30000) {

        bigCities.push(cities[i]);

    }

}

console.log(bigCities);

Output:

[

 { name: "Hyderabad", population: 40000 },

 { name: "Karnool", population: 36000 },

 { name: "Kadapa", population: 37000 }

]

With filter method:

let bigCities = cities.filter(e => {

    return e.population > 30000;

});

console.log(bigCities);

Output:

[

 { name: "Hyderabad", population: 40000 },

 { name: "Karnool", population: 36000 },

 { name: "Kadapa", population: 37000 }

]


Reference:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter




Saturday, 25 September 2021

Custom Lookup with multiple record selection lwc

 Hi,

Here are we are going to learn how to design custom lookup with multi-selection with the help of lightning-pill-container.

For designing custom lookup, we are simply using CSS from Lightning Design System here.

customlookup.html

<template>
    <div class="slds-p-horizontal_small">
        <div class="row">
            <div class="slds-form-element">
                <div class="slds-form-element__control">
                    <div class="slds-combobox_container">
                        <div 
                            class="slds-combobox slds-dropdown-trigger 
                            slds-dropdown-trigger_click" aria-expanded="false"
                            aria-haspopup="listbox" role="combobox">
                            <div class="slds-combobox__form-element 
                                slds-input-has-icon slds-input-has-icon_right"
                                role="none">
                                <lightning-input type="text" id="combobox-id-16" 
                                    value={accountName}
                                    onchange={handleKeyChange} 
                                    onkeydown={handleClick} onclick={handleClick}
                                    onblur={handleClick} 
                                    aria-activedescendant="option1" label='Account'
                                    aria-autocomplete="list" 
                                    aria-controls="listbox-id-12" role="textbox"
                                    placeholder="Search..."></lightning-input>                                  
                            <button
                                    class="slds-button 
                                slds-button_icon slds-input__icon 
                                slds-input__icon_right searchButtonStyle"
                                    title="Remove selected option">
                                    <lightning-button-icon 
                                            icon-name="utility:search" variant="bare" 
                                            alternative-text="Search"
                                             aria-hidden="true" 
                                        onclick={handleOpenModal}>
                                    </lightning-button-icon>
                           </button>    
                            </div>
                            <!-- Start : Parent Search Result -->
                            <div if:true={messageResult}>
                                No Result Found!
                            </div>
                            <template if:true={showSearchedValues}>
                                <div class="slds-box" 
                                    style="height: 130px; 
                                    overflow-y: scroll;">
                                    <ul class="" role="">
                                        <template for:each={accountList} 
                                                for:item="actObj">
                                            <li 
                                               class="slds-p-around_x-small" 
                                               style="cursor: pointer;" 
                                               key={actObj.Id}
                                               onclick={handleParentSelection} 
                                               data-value={actObj.Id}
                                               data-label={actObj.Name}>
                                               {actObj.Name}
                                            </li>
                                        </template>
                                    </ul>
                                </div>
                            </template>
                        </div>      
                            <template if:true={isShowPillContainer}>
                                <lightning-pill-container
                                     items={pillRecordsList}
                                    onitemremove={handleItemRemove}>
                                </lightning-pill-container>  
                            </template>
                                        
                    </div>
                    
                </div>
            </div>
        </div>
    </div>

    <section role="dialog" if:true={isshow}  tabindex="-1" 
            class="slds-modal slds-fade-in-open" 
                aria-labelledby="modal-heading-01" 
                aria-modal="true" aria-describedby="modal-content-id-1">
            
        <div class="slds-modal__container">
          <header class="slds-modal__header">
            <lightning-button-icon
            icon-name="utility:close"
            variant="bare"
            onclick={handleCloseModal}
            alternative-text="Close window" style="float: right;">
        </lightning-button-icon>
            <h2 id="modal-heading-01" class="slds-modal__title 
                slds-hyphenate">
                Account Creation
            </h2>
          </header>
          <div class="slds-modal__content slds-p-around_medium" 
                id="modal-content-id-1">
            <lightning-record-edit-form object-api-name="Account" 
                    onsuccess={handleSuccess}>
                <lightning-messages>
                </lightning-messages>
                <lightning-input-field field-name="Name">
                    
                </lightning-input-field>
                <lightning-input-field field-name="Industry">
                    
                </lightning-input-field>
                <div class="slds-m-top_medium">
                    <lightning-button class="slds-m-top_small" 
                        label="Cancel" 
                        onclick={handleReset}></lightning-button>&nbsp;
                    <lightning-button class="slds-m-top_small" 
                        variant="brand"  
                        type="submit" label="Save Record"></lightning-button>
                </div>
                  
            </lightning-record-edit-form>            
          </div>          
        </div>
      </section>
      <div class="slds-backdrop slds-backdrop_open" if:true={isshow}>
        </div>
</template>

customlookup.js

   
import { LightningElement,wire,track } from 'lwc';
import getAccounts 
    from '@salesforce/apex/AccountSearchController.getAccounts';
export default class CustomLookup extends LightningElement {
        accountName = '';
        accountList = [];     
        accountId
        isshow=false;
        messageResult=false;
        isShowResult = true;   
        showSearchedValues = false;   
        @track pillRecordsList = [];
        pillRecordIdList = [];
        isShowPillContainer = false;
        @wire(getAccounts, {actName:'$accountName'})
        retrieveAccounts ({errordata}) {
        this.messageResult=false;
        if (data) {
            // TODO: Error handling 
            console.log('data::'+data.length);
            if(data.length>0 && this.isShowResult){
                this.accountList = data;                
                this.showSearchedValues = true
                this.messageResult=false;
            }            
            else if(data.length==0){
                this.accountList = [];                
                this.showSearchedValues = false;
                if(this.accountName!='')
                    this.messageResult=true;               
            }  
                
        } else if (error) {
            // TODO: Data handling
            this.accountId =  '';
            this.accountName =  '';
            this.accountList=[];           
            this.showSearchedValues = false;
            this.messageResult=true;   
        }
    }
    handleClick(event){
        this.isShowResult = true;   
        this.messageResult=false;        
    }
    handleKeyChange(event){       
        this.messageResult=false
        this.accountName = event.target.value;
    }  
    handleParentSelection(event){        
        this.showSearchedValues = false;
        this.isShowResult = false;
        this.messageResult=false;
        //Set the parent calendar id
        this.accountId =  event.target.dataset.value;
        //Set the parent calendar label
        this.accountName =  event.target.dataset.label;   
        if(!this.pillRecordIdList.includes(this.accountId)){
            let record = {"type":"icon""label": this.accountName,
                "iconName": "standard:account","name": this.accountId};  
            console.log('accountId::'+this.accountId);    
            this.pillRecordsList.push(record);
            if(this.pillRecordsList){
                this.isShowPillContainer = true;
            }
            this.pillRecordIdList.push(this.accountId);
        } 
       
        this.accountName = '';        
    }
    handleOpenModal(event){
        this.isshow = true;
        console.log('balaji:::');
    }
    handleCloseModal(event){
        this.isshow = false;
    }
    handleSuccess(event){       
        this.isShowResult = false;
        this.messageResult=false;
        this.isshow = false;
        this.accountId = event.detail.id;
        console.log(event.detail.id);
        //console.log('JSON OBject:'+JSON.stringify(event.detail));
        this.accountName = event.detail.fields.Name.value;
        if(!this.pillRecordIdList.includes(this.accountId)){
            let record = {"type":"icon""label": this.accountName,
                "iconName": "standard:account","name": this.accountId};  
            console.log('accountId::'+this.accountId);    
            this.pillRecordsList.push(record);
            if(this.pillRecordsList){
                this.isShowPillContainer = true;
            }
            this.pillRecordIdList.push(this.accountId);
        } 
       
        this.accountName = '';
        const selectedEvent = new CustomEvent('selected', { detail: this.accountId });
        // Dispatches the event.
        this.dispatchEvent(selectedEvent);
    }
    handleReset(event) {
        const inputFields = this.template.querySelectorAll(
            'lightning-input-field'
        );
        if (inputFields) {
            inputFields.forEach(field => {
                field.reset();
            });
        }
        this.isshow = false;
    }

    handleItemRemove (event) {
        const name = event.detail.item.name;
        console.log(name + ' pill was removed!');
        const index = event.detail.index;
        this.pillRecordsList.splice(index1);
        if(this.pillRecordsList.length==0){
            this.isShowPillContainer =false;
        }
    }
}


Output:






customlookup.css :

.searchButtonStyle{
    margin-top4px;
    margin-right0px;
}


Reference : 

https://www.lightningdesignsystem.com/components/lookups/#site-main-content

https://developer.salesforce.com/docs/component-library/bundle/lightning-pill-container/example







Wednesday, 28 July 2021

Simple Lightning Component with Wrapper Class

 Hi,

Here we are going to learn how to capture or display the wrapper result with a simple example.

When we want to access the wrapper properties we have to make sure that properties with "@Auraenabled" annotation.

Eg: 

Apex Class : 

public with sharing class WrapExample {
    public class Wrappercls{
        @Auraenabled
        public String firstName{get;set;}
        @Auraenabled
        public String lastName{get;set;}    
    }
    @Auraenabled
    public static Wrappercls getWrapperDetail(){
        Wrappercls wrapObn = new Wrappercls();
        wrapObn.firstName'Navarshi';
        wrapObn.lastName = 'Malem';
        return wrapObn;
    }
}


Aura Component:

<aura:component controller="WrapExample" 
    implements="flexipage:availableForAllPageTypes">
    <aura:attribute name="wrapObj" type="Object" />
    <aura:handler name="init" value="{!this}" action="{!c.retrieveWrapRecord}" />
    <lightning:card title="Wrapper Record Detail" iconName="utility:connected_apps">
        <p class="slds-p-horizontal_small">
        <h1><b>First Name : </b>{!v.wrapObj.firstName}</h1>
        <h1><b>Last Name : </b>{!v.wrapObj.lastName}</h1>
        </p>
    </lightning:card>
</aura:component>

Component Controller:

({
    retrieveWrapRecord : function(componenteventhelper) {
        var action = component.get("c.getWrapperDetail");
        action.setCallback(thisfunction(data) {
            component.set("v.wrapObj"data.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})


Reference : 

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex_create.htm




Monday, 26 July 2021

Auto Populate Record Type,other fields and navigate to create page

 Hi,

The record type Id field is case-sensitive when we want to auto-populate with record type.

Sample Example:

var recTypeId = '012XXXXXXXX';

var createContact= $A.get("e.force:createRecord");

createContact.setParams({

"entityApiName": 'Contact',

"recordTypeId":recTypeId,

"defaultFieldValues": {                            

'LastName':'balaji',

'FirstName':'malem'

}

});

createContact.fire();

Note:

Always add recordTypeId before defaultFieldValues as above.


Sunday, 4 July 2021

Custom Metadata Types CLI Commands with Summer 20 Release

Hi,

With Summer 20 release we have very important CLI Commands for Custom Metadata Types

These new commands simplify development and help you build automation and synchronize your source from scratch orgs when working with custom metadata types.

The Salesforce CLI custom metadata types commands are available in v49.0.The Salesforce CLI custom metadata types commands are available in v49.0.

  • sfdx force:cmdt:create Creates a new custom metadata type in the current project.
  • sfdx force:cmdt:field:create Generates a custom metadata field based on the field type provided.
  • sfdx force:cmdt:generate Generates a custom metadata type and all its records for the provided sObject.
  • sfdx force:cmdt:record:create Creates a new record for a given custom metadata type in the current project.
  • sfdx force:cmdt:record:insert Creates new custom metadata type records from a CSV file.



EXAMPLE Insert records into an existing custom metadata type from a CSV file.

Create a CSV file and provide the API name of the custom metadata type in the insert command. For example,

NameCountryCode__cCountryName__c
AustraliaAUAustralia
BrazilBZBrazil
CanadaCACanada
sfdx force:cmdt:record:insert 
-f ~/Downloads/CMT_CSV\ -\ sfdx\ force_cmdt_record_insert\ Country\ Data\ -\ CMT_country.csv -t CmdtCountry

 


Reference:

https://releasenotes.docs.salesforce.com/en-us/summer20/release-notes/rn_forcecom_dev_cmt_cli.htm?edition=&impact=

https://help.salesforce.com/articleView?id=sf.custommetadatatypes_cli.htm&type=5


What’s the difference between Einstein Article Recommendations and Suggested Articles?

How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...