Posts

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