Posts

Showing posts with the label LWC

Salesforce Fact #944 | Getting record id in utility bar LWC

If we have an LWC component in the utility bar, we can get record id in the context of a record detail page. For this, we need to check if CurrentPageReference type is standard__recordPage. Reference:  https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_js_lightning_utility_bar_page_context.htm

Salesforce Fact #939 | LWC bind HTML classes

Image
From LWC api version 62.0 onwards, we can manipulate an element or component's class list by using the class attribute. Instead of doing string concatenation, we can return an object or array for complex class names using a getter. It will eventually be rendered as a space separated string of class names. Reference:  https://developer.salesforce.com/docs/platform/lwc/guide/create-components-class-binding.html Attached are the screenshots.

Salesforce Fact #937 | Dynamic import of LWC

Image
With the Winter'24 release, we can use dynamic import for LWC components. Few things to keep a check: 1) The api version of the LWC should be >= 55.0 2) Lightning Web Security must be enabled in session settings. 3) The XML config file should use the lightning__dynamicComponent capability. However, we need to consider the performance overhead while using dynamic import and should use it selectively. Attached are the screenshots of an example. Reference:  https://developer.salesforce.com/docs/platform/lwc/guide/js-dynamic-components.html

Salesforce Fact #918 | Pass value from LWC to embedded screen flow reactively

Image
Suppose we have an embedded screen flow in LWC and we are passing data from lightning record picker in LWC to the screen flow and we want that the change in record picker is reflected in screen flow instantly. We can achieve the same using bit of LWC logic. Reference:  https://salesforce.stackexchange.com/questions/408371/how-to-dynamically-change-flow-embedded-inside-lwc Attached are the screenshots.

Salesforce Fact #908 | Check if current org is sandbox in LWC

Image
How to check if the current org is sandbox in LWC? One option is to call an apex method and get the data. Another option is we can use a custom field and LWC to get the data. In this approach, we create one formula field on the User object to store the current org id and then using this one, we get the IsSandbox value using getRecord on Organization object. Attached are the screenshots.

Salesforce Fact #903 | Check Lead coversion access in LWC

Image
How to check if the current user has access to convert lead or view and edit converted leads in LWC. User permission checks to the rescue. We can use the two user permissions: ConvertLeads and AllowViewEditConvertedLeads to check the same. Reference:  https://www.sfdcamplified.com/challenge-map-between-salesforce-permissionname-and-label/ Attached is the screenshot.

Salesforce Fact #899 | LWC record picker with custom settings and metadata

Image
Lightning record picker works with Custom Settings and Custom metadata as well. Attached are the screenshots.

Salesforce Fact #895 | Dependent record picker in LWC

Image
We can create a dependent lightning record picker in LWC. Suppose, we have two record pickers and once the account record is selected, the second record picker should filter out the related contacts. Reference:  https://salesforce.stackexchange.com/questions/428066/lightning-record-picker-dynamic-record-filter-not-working Attached are the code snippets.

Salesforce Fact #892 | Parent record access missing in LWC getRecord

Image
While using getRecord in LWC, if the user does not have access to the parent record the parent field values are shown as null but there is no error encountered. In this example, we have an Account lookup on Lead record and fetching the Rating and Account Owner name using getRecord. Attached are the screenshots.

Salesforce Fact #888 | Handle error in common getRecords LWC

Image
Suppose you have an LWC which has a getRecord and is getting used across multiple object record pages. Now, if the fieldList is not consistent with the recordId then error is encountered. So, in order to handle this, we can check the sobjecttype and for the respective sobject we can return respective fields and if there is no logic built yet for any sobject, we can just pass the Id or empty array in the fields property to avoid the error. Attached is the screenshot.

Salesforce Fact #887 | fields empty on LWC getRecords

Image
If the fields parameter in LWC getRecords is an empty array, then it returns no data neither it returns any error. It just skips the execution of the getRecords. Note: This is just a POC and ideally the fields array won't be empty. Attached are the screenshots.

Salesforce Fact #884 | LWC getRecord optionalFields in action

Image
The LWC getRecord optionalFields parameter is pretty helpful to deal with fields which have been used in the getRecord but the current user does not have access to. If we specify the same field in fields parameter, the call to getRecord fails with error, while if the same field is used in optionalFields it is ignored and the data is returned for the rest of the fields. In this example, the current user does not have access to the Account Description field. Reference:  https://developer.salesforce.com/docs/platform/lwc/guide/reference-wire-adapters-record.html Attached are the screenshots.

Salesforce Fact #882 | Handling decimal data in LWC returned from apex wrapper

Image
We need to be careful while dealing with large decimal values in LWC returned from apex in wrapper structure. If the value is large, it is converted to String to avoid any loss of precision. Reference:  https://salesforce.stackexchange.com/questions/327214/lwc-autoconverting-decimal-into-string-sf-bug Attached are the screenshots.

Salesforce Fact #877 | Exploring lwc-codemod tool

Image
At times, we face difficulty in debugging syntax issues in HTML file in LWC. The lwc-codemod tool can help on resolving few of the HTML syntax errors. To get this working, once the tool is installed, we need to use the following command: lwc-codemod html-template-cleanup <path> path is the directory where the LWC is located. Reference:  https://github.com/salesforce/lwc-codemod?tab=readme-ov-file Attached are example screenshots.

Salesforce Fact #868 | Show entered password in LWC

Image
In most of the login pages, we have a checkbox option to show the entered password. We can implement the same in LWC with a bit of logic. Attached are the screenshots.

Salesforce Fact #867 | Getting users for selected user role in screen flow

Image
Here's another example of screen flow reactivity along with LWC lightning record picker. In this example, we have a picklist of list of user roles in screen flow and on selecting a role, we are showing a filtered record picker with users corresponding to the selected role. Attached are the screenshots.

Salesforce Fact #857 | BatchApexErrorEvent subscribe using LWC

Image
BatchApexErrorEvent can be subscribed in LWC as well. For this, we have to import the required functions from lightning/empApi module and the channel name is '/event/BatchApexErrorEvent'. In this example, we have subscribed to the  BatchApexErrorEvent using LWC and showing a toast error message on receiving the error. References:  https://developer.salesforce.com/docs/component-library/bundle/lightning-emp-api/documentation https://salesforce.stackexchange.com/questions/297863/showtoast-from-messagecallback-function-of-empapi Attached are the screenshots.

Salesforce Fact #855 | Dynamic record picker in LWC

Image
We have a dynamic record picker in LWC. Using the combobox we can select the sobject and based on that we can set the objectApiName of the lightning record picker. Attached are the screenshots.