Lightning Standard APIs

The lightning standard APIs given by Salesforce are as follows:

  • uiListAPI
  • uiListsAPI
  • uiAppApi
  • uiRecordApi
  • uiObjectInfoAPI
  • uiRelatedListApi

 

  1. uiListAPI :

This uiListAPI module is deprecated; instead of this, mostly used is uiListsAPI. getListUi gets list view records and metadata for a list view by:

  • List view API name
  • List view ID
  • API name of supported object

 

  1. uiListsAPI : 

This API includes wire adapters to get the list view metadata for a list view by this api name. It includes the following wire adapter methods:

  • getListInfoByName

            This Wire Adapter is used to get the metadata for the list view. 

     Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getListInfoByName } from ‘lightning/uiListsApi’;

import ACCOUNT_OBJECT from ‘@salesforce/schema/Account’; 

 

export default class Example extends LightningElement {

    @wire(getListInfoByName, { objectApiName: ACCOUNT_OBJECT, listViewApiName: ‘AllAccounts’ })

    propertyOrFunction;

}

 

  • getListInfosByName:

This Wire Adapter is used to get the metadata for the batch of the list view. 

Syntax:

import { getListInfosByName } from ‘lightning/uiListsApi’;

import ACCOUNT_OBJECT from ‘@salesforce/schema/Account’;

export default class KeywordResults extends LightningElement {

  @wire(getListInfosByName, {

        names: [‘${ACCOUNT_OBJECT.objectApiName}.AllAccounts’]

    })

    getListInfosByNameWire({ data }) {

        if (data && data.results) {

            this.listInfos = data.results.map(({ result }) => result);

        }

    }

}

 

  1. uiAppAPI :

It is for evaluation purposes only, not for production use. It’s offered as is and isn’t supported, and Salesforce has no liability for any harm or damage arising out of or in connection with it.   

  • getNavItems

This uses a wire adapter to retrieve the items in the navigation menu.

Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getNavItems } from ‘lightning/uiAppsApi’;

import FORM_FACTOR from ‘@salesforce/client/formFactor’;

 

export default class Example extends LightningElement {

    @api tabs = [‘standard-Account’, ‘standard-CollaborationGroup’];

    @wire(getNavItems, {

        formFactor: FORM_FACTOR,

        navItemNames: ‘$tabs’,

        pageSize: 30,

    })

    propertyOrFunction;

 

  1. uiRecordApi :

This API contains wire adapters to record data and get default values to create records. It also includes JavaScript APIs to create, delete, update, and refresh records.

It includes the methods as follows:

 

1] createRecord(recordInput) :

     It is used to create records in salesforce. Creating the documents is more beneficial because it does not require apex class.

Syntax:

import { createRecord } from ‘lightning/uiRecordApi’;

createRecord(recordInput: Record): Promise<Record>

 

2] createRecordInputFilteredByEditedFields(recordInput, originalRecord) :

      Creates a RecordInput object with a list of fields edited from their original values to pass in a call to update the record(recordInput).

    Syntax:

import { createRecordInputFilteredByEditedFields } from ‘lightning/uiRecordApi’;

createRecordInputFilteredByEditedFields(recordInput: Record, originalRecord: Record): Record

 

3] deleteRecord(recordId):

      It is used to delete the records from the salesforce database without calling the apex class.

Syntax: 

import { deleteRecord } from ‘lightning/uiRecordApi’;

deleteRecord(recordId: string): Promise<void>

 

4] generateRecordInputForCreate(record,objectInfo) :

     Generates a representation of a record (Record Input) that can use to create a record using create a record(RecordInput). Passing in ObjectInfo filters the Record Input to only fields that are creatable.

Syntax:

import { generateRecordInputForCreate } from ‘lightning/uiRecordApi’;

generateRecordInputForCreate(record: Record, objectInfo?: ObjectInfo): RecordInput

 

5] generateRecordInputForUpdate(record, objectInfo) :

    Generates a representation of a record (Record Input) that can use to update a form using updateRecord(recordInput). Passing in ObjectInfo filters the Record Input to only updateable fields.

Syntax:

import { generateRecordInputForUpdate } from ‘lightning/uiRecordApi’;

generateRecordInputForUpdate(record: Record, objectInfo?: ObjectInfo): RecordInput

 

6] getFieldValue(record, field) :

    Gets a field’s value from a record. Spanning fields are supported.

Syntax:

import { getFieldValue } from ‘lightning/uiRecordApi’;

getFieldValue(record: Record, field: string)

   

7] getFieldDisplayValue(record, field) :

Gets the display value of a field. Spanning fields are supported.

Syntax:

import { getFieldDisplayValue } from ‘lightning/uiRecordApi’;

getFieldDisplayValue(record, field)

 

8] getRecord :

      This wiring adapter used to obtain the records from the salesforce database. 

Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getRecord } from ‘lightning/uiRecordApi’;

@wire(getRecord, { recordId: string, fields: string|string[], optionalFields?: string|string[] })

propertyOrFunction

 

@wire(getRecord, { recordId: string, layoutTypes: string|string[],

                   modes?: string|string[], optionalFields?: string|string[] })

propertyOrFunction

 

9] getRecords :

    This wiring adapter is used to obtain the batch of records at once from the salesforce database.

Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getRecords } from ‘lightning/uiRecordApi’;

 

@wire(getRecords, { records: [ { recordIds: string[], fields: string[] } ] })

propertyOrFunction

 

@wire(getRecords, { records: [ { recordIds: string[], fields: string[], optionalFields?: string[] } ] })

propertyOrFunction

 

10] getRecordCreateDefaults :

      Use this wired adapter to obtain default information and data needed to create a record.

Syntax: 

import { getRecordCreateDefaults } from ‘lightning/uiRecordApi’;

@wire(getRecordCreateDefaults, { objectApiName: string })

propertyOrFunction;

 

11] getRecordNotifyChange(recordIds):

      Fetch record updates for the specified record IDs and refresh the Lightning Data Service cache, providing your wires with the latest record data. Call this function to notify Lightning Data Service that a record has changed outside its mechanisms, such as via imperative Apex or Visualforce or by calling User Interface API via a third-party framework.

Syntax:

import { getRecordNotifyChange } from ‘lightning/uiRecordApi’;

getRecordNotifyChange(items: Array<{recordId: string}>)

 

12] getRecordUi (Deprecated) :

       Use this wired adapter to obtain layout information, metadata, and data to build UI for one or more records.

Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getRecordUi } from ‘lightning/uiRecordApi’;

 

export default class Example extends LightningElement {

  @wire(getRecordUi, { recordIds: string|string[], layoutTypes: string|string[],

                       modes: string|string[], optionalFields?: string|string[] })

  propertyOrFunction;

}

 

13] updateRecord(recordInput, clientOptions)

       This method is used to update records. recordInput parameter takes record of the record to update

Syntax:

import { updateRecord } from ‘lightning/uiRecordApi’;

updateRecord(recordInput: Record, clientOptions?: Object): Promise<Record>

 

  1. uiObjectInfoAPI :

This is used to obtain object metadata and obtain picklist values.

This contains the following methods:

 

1] getObjectInfo :

  Use this wired adapter to obtain metadata about a specific object. The response includes metadata describing the object’s fields, child relationships, record type, and theme.

Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getObjectInfo } from ‘lightning/uiObjectInfoApi’;

import ACCOUNT_OBJECT from ‘@salesforce/schema/Account’;

 

export default class Example extends LightningElement {

    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })

    propertyOrFunction;

}

 

2] getObjectInfos :

Use this wired adapter to obtain metadata for multiple objects. The response includes metadata describing each object’s fields, child relationships, record type, and theme.

Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getObjectInfos } from ‘lightning/uiObjectInfoApi’;

import ACCOUNT_OBJECT from ‘@salesforce/schema/Account’;

import OPPORTUNITY_OBJECT from ‘@salesforce/schema/Opportunity’;

 

export default class GetObjectInfosExample extends LightningElement {

    @wire(getObjectInfos, { objectApiNames: [ ACCOUNT_OBJECT, OPPORTUNITY_OBJECT ] })

    propertyOrFunction;

}

 

3] getPicklistValues :

Use this wired adapter to obtain the picklist values for a specified field.

Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getPicklistValues } from ‘lightning/uiObjectInfoApi’;

import INDUSTRY_FIELD from ‘@salesforce/schema/Account.Industry’;

 

export default class Example extends LightningElement {

    @wire(getPicklistValues, { recordTypeId: ‘012000000000000AAA’, fieldApiName: INDUSTRY_FIELD })

    propertyOrFunction;

}

 

4] getPicklistValuesByRecordType :

Use this wired adapter to obtain the values for every picklist of a specified record type.

Syntax:

import { LightningElement, wire } from ‘lwc’;

import { getPicklistValuesByRecordType } from ‘lightning/uiObjectInfoApi’;

import ACCOUNT_OBJECT from ‘@salesforce/schema/Account’;

 

export default class Example extends LightningElement {

    @wire(getPicklistValuesByRecordType, { objectApiName: ACCOUNT_OBJECT, recordTypeId: ‘012000000000000AAA’ })

    propertyOrFunction

}

 

  1. uiRelatedListApi :

This obtain related list metadata and record data.

This contains the following methods:

1] getRelatedListCount

   Use this wire adapter to obtain the RelatedList record count.

Syntax: 

import { LightningElement, wire } from ‘lwc’;

import { getRelatedListCount } from ‘lightning/uiRelatedListApi’;

export default class LdsGetRelatedListCount extends LightningElement {

    @wire(getRelatedListCount, {

        parentRecordId: ‘001RM000003UNu6YAG’,

        relatedListId: ‘Contacts’,

    })

}

 

2] getRelatedListInfo

   Use this wire adapter to obtain the metadata for RelatedList.

Syntax: 

import { LightningElement, wire } from ‘lwc’;

import { getRelatedListInfo } from ‘lightning/uiRelatedListApi’;

import ACCOUNT_OBJECT from ‘@salesforce/schema/Account’;

export default class LdsGetRelatedListInfo extends LightningElement {

    @wire(getRelatedListInfo, {

        parentObjectApiName: ACCOUNT_OBJECT,

        relatedListId: ‘Contacts’,

        recordTypeId: ‘012000000000000AAA’ //optional

    })

 

3] getRelatedListInfoBatch

    Use this wire adapter to obtain the metadata for a batch of RelatedLists.

Syntax: 

import { LightningElement, wire } from ‘lwc’;

import { getRelatedListInfoBatch } from ‘lightning/uiRelatedListApi’;

import ACCOUNT_OBJECT from ‘@salesforce/schema/Account’;

 

export default class LdsGetRelatedListInfoBatch extends LightningElement {

    @wire(getRelatedListInfoBatch, {

        parentObjectApiName: ACCOUNT_OBJECT,

        relatedListNames: [‘Contacts’, ‘Opportunities’],

    })

}

 

4] getRelatedListRecords

   Use this wire adapter to obtain RelatedList records.

Syntax: 

import { LightningElement, wire } from ‘lwc’;

import { getRelatedListRecords } from ‘lightning/uiRelatedListApi’;

 

export default class LdsGetRelatedListRecords extends LightningElement {

    @wire(getRelatedListRecords, {

        parentRecordId: ‘001RM000003UNu6YAG’,

        relatedListId: ‘Contacts’,

        fields: [‘Contact.Name’,’Contact.Id’],

        sortBy: [‘Contact.Name’]

    })

}

 

5] getRelatedListRecordsBatch

   Use this wire adapter to obtain records for a batch of RelatedLists.

  Syntax: 

import { LightningElement, wire } from ‘lwc’;

import { getRelatedListRecordsBatch } from ‘lightning/uiRelatedListApi’;

 

export default class LdsGetRelatedListRecordsBatch extends LightningElement {

    @wire(getRelatedListRecordsBatch, {

        parentRecordId: ‘001RM000003UNu6YAG’,

        relatedListParameters: [

            {

                relatedListId: ‘Contacts’,

                fields: [‘Contact.Name’,’Contact.Id’],

                sortBy: [‘Contact.Name’]

            },

            {

                relatedListId: ‘Opportunities’,

                fields: [‘Opportunity.Name’, ‘Opportunity.Amount’],

                sortBy: [‘Opportunity.Amount’],

                where: “{ and: [{ Name: { like: \”ACME%\” }}] }”

            }

        ]

    })

}

 

6] getRelatedListsInfo

    This wire adapter used to obtain the metadata for relatedLists in an object default layout.

 Syntax: 

import { LightningElement, api, wire, track } from ‘lwc’;

import { getRelatedListsInfo } from ‘lightning/uiRelatedListApi’;

import ACCOUNT_OBJECT from ‘@salesforce/schema/Account’;

 

export default class LdsGetRelatedListsInfo extends LightningElement {

    @wire(getRelatedListsInfo, {

        parentObjectApiName: ACCOUNT_OBJECT,

        recordTypeId: ‘012000000000000AAA’// optional

    })

}

 

Note: Examples Referenced from developer.salesforce.com

Spread the updates
September 9, 2022
|

Leave a reply