Posts

Showing posts from August, 2025

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 #938 | SOQL for loop limit error

Image
Have you encountered the error:  System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop. The error is encountered when SOQL For loop is used on a parent to child SOQL and the child record list contains 200 or more records. To resolve this, we need to run a separate for loop on the child records. 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 #936 | USING SCOPE delegated in SOQL

There is a SCOPE named 'delegated' in SOQL. It returns the records which have been delegated to some other user. For example, the below queries return the tasks or events which are assigned to different user after the initial assignment. Select Id FROM Task USING SCOPE delegated Select Id FROM Event USING SCOPE delegated Note: the queries return data in context of the previous user.

Salesforce Fact #935 | Get country prefix using screen action

Image
We can show the country prefix code with the help of screen action. In this example, we have created a custom metadata to store the country code and respective prefix value. Now, in the screen flow, on selecting a country picklist value we can pass the entire metadata list and the selected country value to a subflow in order to get the prefix and show the same in the screen instantaneously.  Attached are the screenshots.

Salesforce Fact #934 | Disabling picklist on selecting value in screen flow

Image
Suppose we have a scenario where we have a picklist in a screen flow and once a value is selected, the picklist should get disabled. We can implement it using screen action. In this example, we have a picklist with two values A and B in a screen flow. Whenever a value is selected, it is sent to an autolaunched flow and it returns a boolean value in response which is used in the disabled attribute of the picklist input. The catch is we need to create a formula resource to store the value of the selected picklist, directly passing it would always be received as null in the subflow. Attached are the screenshots.

Salesforce Fact #933 | Query row count for parent to child soql

The query rows count is a bit different in case of SOQL with parent to child subquery. For example, if there are 5 accounts each having 2 contacts in the org, then the below query would return 15 query rows while calling Limits.getQueryRows(): [SELECT Id, (SELECT Id FROM Contacts) FROM Account] i.e. total number of accounts + total number of contacts with related accounts Reference:  https://salesforce.stackexchange.com/questions/184131/what-is-the-limit-for-subquery-in-soql

Salesforce Fact #932 | List of current logged in users

There is an object AuthSession which can be queried to get the list of users currently logged in to the org. example query: Select id, Users.name, CreatedDate, LoginType, SessionType, IsCurrent from AuthSession Reference:  https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_authsession.htm

Salesforce Fact #931 | Performing aggregation using transform element

Image
We can perform aggregation operations as well using the transform element in flow. For this, we need to create an apex class with the AuraEnabled variables to store the aggregated value and refer the same in the transform element. This avoids the need for using loop. In this example, we are getting the sum of number of employees across all the accounts. Attached are the screenshots. Reference:  https://help.salesforce.com/s/articleView?id=platform.flow_build_logic_transform_sum_or_count.htm&type=5

Salesforce Fact #930 | Need to be careful while changing OWD to Public Read/Write

If we have used the share object of any custom object in apex or flow logic, we need to be careful while changing its OWD to Public Read/Write. While changing the OWD it won't show any reference error and trying to run the logic afterwards would show the below error: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: AccessLevel (trivial share level Read, for organization with default level Edit): [AccessLevel]

Salesforce Fact #929 | Nth highest in screen flow

Image
We can find the Nth highest value in screen flow using Get Records with a bit of logic. For example, we want to find the Nth highest NumberOfEmployees value across all the accounts. The idea is to fetch the records and then run a check to iterate over the records as long as the temp variable value is less than N value. The temp variable is initialized to 1. In the assignment we would keep on removing the first record. At the end, we will pick the first record from the collection. Attached are the screenshots. Note: this is just a POC flow and the error handlings, best practices are not covered.