Sunday 19 June 2022

 getRelatedListsInfo

Use this wire adapter to get the metadata for RelatedLists in an object’s default layout.

Parameters

  • parentObjectApiName—(Required) The API name of a parent object that you want to get related lists for, like an Account.
  • recordTypeId—(Optional) The ID of the parent record type.

Usage

This code example fetches the related lists info by API name of the parent object, then iterates through the related lists.

HTML

<template>
    <lightning-card title="Related List of Account">
        <template if:true={relatedLists}>
            <div class="slds-m-around_medium">
                <template for:each={relatedLists} for:item="relatedList">
                    <p key={relatedList.label}>
                        {relatedList.label}
                    </p>
                </template>
            </div>
        </template>
    </lightning-card>
</template>


JS

import { LightningElement,wire} from 'lwc';
import { getRelatedListsInfo } from 'lightning/uiRelatedListApi';
export default class GetRelatedListDetails extends LightningElement {
    error;
    relatedLists;
    @wire(getRelatedListsInfo, {
        parentObjectApiName: 'Account',
       
    })listInfo({ error, data }) {
        if (data) {
            this.relatedLists = data.relatedLists;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.relatedLists = undefined;
        }
    }
}

XML

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

</LightningComponentBundle>

RESULT:





 getRelatedListRecords

Use this wire adapter to get RelatedList records.

Parameters

  • parentRecordId—(Required) The ID of the parent record that you want to get related lists for, like an Account ID.
  • relatedListId—(Required) The API name of a related list object, like Contacts, Opportunities, or Cases.
  • fields—(Optional) The API names of the related list’s column fields.
  • optionalFields—(Optional) The API names of additional fields in the related list.
  • pageSize—(Optional) The number of list records to return per page.
  • sortBy—(Optional) An array of field API names to sort the related list by. Accepts only one value per request.
  • where—(Optional) The filter to apply to related list records, in GraphQL syntax.
This code example fetches the record for the Opportunity-related list in the Account object, then iterates the opportunity to display the Id and Name.


HTML

<template>
    <lightning-card title="Opportunity Related List Records">
        <template if:true={records}>
            <div class="slds-m-around_medium">
                <template for:each={records} for:item="rec">
                    <p key={rec.fields.Id.value}>
                        {rec.fields.Id.value} -  {rec.fields.Name.value}
                    </p>
                </template>
            </div>
        </template>
    </lightning-card>

</template>

JS
import { LightningElement,wire} from 'lwc';
import { getRelatedListRecords } from 'lightning/uiRelatedListApi';
export default class GetRelatedListRecords extends LightningElement {
    error;
    records;
    @wire(getRelatedListRecords, {
        parentRecordId: '0010I00002Zq6IMQAZ',
        relatedListId: 'Opportunities',
        fields: ['Opportunity.Id','Opportunity.Name']
    })listInfo({ error, data }) {
        if (data) {
            this.records = data.records;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.records = undefined;
        }
    }
}

XML
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>54.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
         <target>lightning__RecordPage</target>
    </targets>

</LightningComponentBundle>


RESULT




 getRelatedListInfo

Use this wire adapter to get the metadata for RelatedList.

  • parentObjectApiName—(Required) The API name of a parent object that you want to get related lists for, like an Account.
  • relatedListId—(Required) The API name of a related list object such as Contacts, Opportunities, or Cases.
  • recordTypeId—(Optional) The ID of the parent record type. If not provided, the default record type is used.

This code example fetches the metadata for the Opportunity-related list in the Account object, then iterates through the list of display columns.


HTML

<template>
    <lightning-card title="Get Opportunity Related List Information">
        <template if:true={displayColumns}>
            <div class="slds-m-around_medium">
                <template for:each={displayColumns} for:item="info">
                    <p key={info.fieldApiName}>
                        {info.label}
                    </p>
                </template>
            </div>
        </template>
    </lightning-card>
</template>

JS

import { LightningElement,wire } from 'lwc';
import { getRelatedListInfo } from 'lightning/uiRelatedListApi';
export default class GetRelatedListInfo extends LightningElement {
    error;
    displayColumns;
    @wire(getRelatedListInfo, {
        parentObjectApiName: 'Account',
        relatedListId: 'Opportunities',
    })listInfo({ error, data }) {
        if (data) {
            console.log('data',JSON.stringify(data))
            this.displayColumns = data.displayColumns;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.displayColumns = undefined;
        }
    }
}

XML

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

RESULT








Get Related List Record Count

Use this wire adapter to get the RelatedList record count.

 This code example fetches the record count for a related list.

  • parentRecordId—(Required) The ID of the parent record that you want to get related lists for, like an Account ID.
  • relatedListId—(Required) The API name of a related list object such as Contacts, Opportunities, or Cases.

HTML

<template>
    <lightning-card title="getRelatedListCount">
        <div class="slds-var-p-around_medium">
          <template if:true={responseData}>
            <div>No of opportunities in account related list - {responseData.count}</div>
          </template>
        </div>
      </lightning-card>
</template>

JS

import { LightningElement,wire} from 'lwc';
import {getRelatedListCount} from 'lightning/uiRelatedListApi';
export default class GetReleatedListCount extends LightningElement {
    responseData;
    error;
    @wire(getRelatedListCount, {
      parentRecordId:'0010I00002Zq6IMQAZ', // AccountId
      relatedListId:'Opportunities' //RelatedList object Name
    })listInfo({error, data}){
      if(data){
         this.responseData = data;
         this.error = undefined;
      }
      if(error){
        this.error = error;
        this.responseData = undefined;
      }
    }
  }
 

XML

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

</LightningComponentBundle>

RESULT




Sunday 6 March 2022

                              ONLOAD IN AURA VS LIGHTNING WEB COMPONENT

If we embedded LWC component inside the aura component which onload method will call first (doinit/connectCallback)?. For understanding this we are going to create two Lightning components.

  1. customAuraComponent – Aura Component 
  2. customLwc – LWC Component.

Step 1: Create customAuraComponent  (Developer console -> New -> LightningComponent)

customAuraComponent 

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,
flexipage:availableForRecordHome,force:hasRecordId,
forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doinit}"></aura:handler>
    <lightning:card title="Cutsom Aura Component"></lightning:card>
    <!-- LWC Component -->
    <c:customLwc/>
</aura:component>


Javascript

doinit:function(component, event, helper) {          console.log('onload:aura component') }


Step 2: Create LWC component 

customLwc
<template>
    <p> LWC Component</p>
</template>

Javascript
import { LightningElement } from 'lwc';

export default class CustomLwc extends LightningElement {
    connectedCallback(){
        console.log("onload:LWC Component");
    }
}


XML:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__HomePage</target>
    </targets>
</LightningComponentBundle>


Result :

The init handler in Aura gets fired first then connectedCallback in Lightning Web Component





Saturday 5 March 2022

                                DYNAMIC CSS IN LIGHTNING WEB COMPONENT

This post explains how to create CSS in lightning web components and also how to use the dynamic CSS in web components using the getter property

Let’s see an example. I have created a Lightning web component named dynamic style. It has a div and a checkbox. Our aim is to change the CSS class of div whenever the checkbox is checked.

dynamicStyle.html

<template>
    <lightning-card title="Dynamic CSS using Getter">
        <div class={dynamicColorChange}>
            Dynamic Style
        </div>
        <lightning-input type="checkbox" label="ChangeStyle" value={changeColor} onchange={handleChange}>
        </lightning-input>
    </lightning-card>
</template>

Javascript

import { LightningElement } from 'lwc';

export default class DynamicStyle extends LightningElement {
    changeColor;
    handleChange(event){
        this.changeColor=event.target.checked;  
    }

    //If change color is true: using getter will return class 1 else class 2
    get dynamicColorChange(){
        return this.changeColor?'class1':'class2';
    }
}

     CSS: The same name as an LWC component and add .css in the file name for this example: dynamicStyle.css

.class1{
   height: 30px;
   background-color: aqua;
}

.class2{
    height:30px;
     background-color: chartreuse;
}


     The onchange handler is defined in the dynamicStyle.js file of the component. It is updating the value of the checkbox to a property defined. Along with it, the js file also has a getter to compute dynamically the CSS class of the div block defined in HTML.

        How to find who created the lightning web component 


 We can find aura and LWC in Setup > Quick find > Lightning Components. The Type column gives information on Aura/LWC. It provides CreatedBy, CreatedDate, and the LastModifiedDate of LWC and Aura.


 

Monday 21 February 2022

 Field History Tracking

  • You can select certain fields to track and display the field history in the History related list of an object. 
  • Field history data is retained for up to 18 months through your org and up to 24 months via the API. 
  • Field history tracking data doesn’t count against your Salesforce org’s data storage limits.


 Salesforce stores an object’s tracked field history in an associated object called StandardObjectNameHistory or CustomObjectName__History.

 For example:

  • AccountHistory represents the history of changes to the values of an Account record’s fields.
  • MyCustomObject__History tracks field history for the MyCustomObject__c custom object.

 General Considerations

  • Salesforce starts tracking field history from the date and time that you enable it on a field. Changes made before this date and time aren’t included and didn’t create an entry in the History related list.
  • Use Data Loader or the queryAll() API to retrieve field history that‘s 18–24 months old. 
  • The Field History Tracking timestamp is precise to a second in time. In other words, if two users update the same tracked field on the same record in the same second, both updates have the same timestamp. Salesforce can’t guarantee the commit order of these changes to the database. As a result, the display values can look out of order.

 Field Audit Trail

  • Field Audit Trail lets you define a policy to retain archived field history data up to 10 years from the time the data was archived. 
  • Field history tracking data and Field Audit Trail data don’t count against your Salesforce org’s data storage limits.
  • Field history is copied from the History-related list into the FieldHistoryArchive big object.
  •  With Field Audit Trail, you can track up to 60 fields per objectWithout it, you can track only 20 fields per object

The following fields can’t be tracked.

  • Formula, roll-up summary, or auto-number fields
  • Created By and Last Modified By
  • Expected Revenue field on opportunities
  • Master Solution Title or the Master Solution Details fields on solutions
  • Long text fields
  • Multi-select fields

 

Sunday 20 February 2022

 

Unable to see the Reset Security Token option                 

There are a few different reasons the Reset Security Token feature may not be available. 

  1. IP Restrictions in the Login IP Ranges
  2. Network Access missing from Security Controls
  3. User Profile is Corrupted
  • IP Restrictions in the Login IP Ranges

          In order for the Reset My Security Token option to appear, you will need to remove the Login IP Ranges or change the User to a profile that does not have Login IP Ranges listed.
 
  • Network Access missing from Security Controls
    System administrators can confirm if Network Access is missing by following these steps:
  1. Go to Setup
  2. On the Quick Find box, enter Network Access.
  3. If you don't see the 'Network Access' link above, the system administrator can log a Case with Support to request the following features enabled for the organization:
  4. Login Challenge Enabled
  5. Login with API Token
  • User Profile is Corrupted
         If none of the previous scenarios are true try editing the User profile that's missing the security token and save it without making any modifications. This will reset the profile and might result in the token option being available.

If the information provided does not resolve the issue open a case with Salesforce Support for assistance.