Posts

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 #886 | Check if account description is blank using flow

Image
Long text area cannot be referenced in Salesforce formula fields. But they can be referenced in flow formula resources. Suppose, we need a flag to indicate if the description field on account is empty or not. We can create a before save record-triggered flow on Account and check if it is blank in a formula resource and store the value in a checkbox field. Attached are the screenshots.

Salesforce Fact #885 | Public group count

With SOQL query, we can get to know the count of public groups inside a Queue. We can make use of the UserOrGroupId field of GroupMember object. Example Query: SELECT Count(Id) FROM GroupMember WHERE Group.Name='Test Lead Queue' AND UserOrGroup.Name = NULL

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 #883 | Careful while accessing getObjectInfo to get record type details

Image
We need to be careful while using getObjectInfo module to access the record types in LWC. We can access the record type name property and there is no developer name property present. The name returns the label of the record type and if translation is present for the user language then the translated value is returned. So, we need to be careful while doing any check to match the record type name. There is an Idea already submitted to add the Developername in the data returned:  https://ideas.salesforce.com/s/idea/a0B8W00000H50x7UAB/include-developername-in-the-recordtypeinfo-returned-with-getobjectinfo-in-lwc 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.