Posts

Showing posts from February, 2024

Salesforce Fact #817 | Map put() method return

Image
The put() method of Map class returns null if it's a new key-value pair which is added. However, if the key was already existing, then put() method returns the old value. This might be helpful when we want to know the old value while replacing the value corresponding to a key. Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_map.htm#apex_System_Map_put Attached is the screenshot.

Salesforce Fact #816 | Char count in long text area in screen flow

Image
We can count the number of chars and show the same for a long text area against the limit in a screen flow. Attached are the screenshots.

Salesforce Fact #815 | Wordcount logic in LWC

Image
We can create a simple word count logic for a long text area in LWC using some JS logic. Note: This doesn't cover consecutive spaces. Reference:  https://salesforce.stackexchange.com/questions/66249/word-count-formula#:~:text=Here%20we%20are%20counting%20the,%2C%22%20%22%2C%22%22)) Attached are the screenshots.

Salesforce Fact #814 | Simplified row returned check on SOQL

Image
With the advent of the new Null Coalescing operator, the row returned check from SOQL has also been simplified. Previously, if a query is expected to return one row and if it does not return any row we used List collection to avoid the error: 'List has no rows for assignment to SObject'. But now, with Null Coalescing operator we can check it using the sobject variable only, no need of List collection. Attached is the screenshot.

Salesforce Fact #813 | Null Coalescing Operator in Apex

In Spring'24 release, we have one new operator in Apex i.e. Null coalescing operator. This is an alterative of the null check of any variable. If the left hand side operator is not null return its value else return the value on the right hand side. Previously: String name; String result =  String.isBlank(name) ? 'test' : name; Now: String name; String result = name ?? 'test'; Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_NullCoalescingOperator.htm Note: It only works with null value, not with other values like 0 or false. Also, this operator is not supported in bind expression in SOQL queries.

Salesforce Fact #812 | Repeater(Beta) component in screen flow

Image
In Spring'24 release, we have the new Repeater(Beta) component introduced in screen flow builder. The input components inside the repeater component are tracked using the AllItems attribute. So, in order to get the length of the repeater collection, we need to iterate over the AllItems list and count its length, since the equals count operator is not supported yet to get the collection length. Reference:  https://help.salesforce.com/s/articleView?id=sf.flow_ref_elements_screencmp_repeater.htm&type=5 Attached are the screenshots. Output:

Salesforce Fact #811 | Careful with map with null value in VF page

Image
We need to be careful while accessing map in VF page. If any of the value in the map needs to be null, we should use '' instead of NULL, else it will throw the error: Map key <corresponding key> not found in map. Attached are the screenshots.

Salesforce Fact #810 | Call parent component method in child LWC

Image
In order to call parent component's method in child LWC component, we can pass the method as a public property from parent to child and then invoke the same in child component. Reference:  https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000C5ddmSAB Attached are the screenshots.

Salesforce Fact #809 | Permission missing errors

At times, you can encounter the below errors: 'API is disabled for this user' -> This is encountered when the user is missing the API enabled system permission. 'limit resource is not enabled' ->  This is encountered when the user is missing the View Setup and Configuration system permission. Reference:  https://salesforce.stackexchange.com/questions/28037/messagelimits-resource-is-not-enabled-errorcodeapi-disabled-for-org

Salesforce Fact #808 | Invoking composite api from Postman

Image
With the help of Composite API, we can insert multiple related Sobject records at once. Thanks to the referenceId attribute. In this example, we have inserted one account and its related contact in a single API call using composite api from Postman. Reference:  https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_composite_record_manipulation.htm?_ga=2.195590892.1551867688.1707766533-2111625757.1696698877 Attached are the screenshots.

Salesforce Fact #807 | Mass delete records

There is an option in Salesforce which allows to mass delete records. Currently it is available for these objects: Accounts, Leads, Activities, Contacts, Cases, Solutions, Products, Reports. Steps: Setup -> Mass Delete Records -> Choose the object as per the need. Reference:  https://help.salesforce.com/s/articleView?id=sf.admin_massdelete.htm&type=5

Salesforce Fact #806 | Flow Transform(Beta) in action

Image
Suppose we need to show the account names in capitalized format after retrieving in screen flow. Now, no need to iterate over the list of accounts. We have the Transform(Beta) component which can take care of the formatting right when the mapping is done. Attached are the screenshots.

Salesforce Fact #805 | $EachItem in Transform element in flow

Image
So we have the Transform(Beta) element in the flow. Using this we transform the data from a record or collection and store it in another record or apex-defined variable. If we see the formula syntax, for collection type it uses the [$EachItem] merge field syntax for iterating over each item in the collection. In this example, we have a get records element which fetches the account records and this is used in the Transform element to get the account names. Reference:  https://help.salesforce.com/s/articleView?id=sf.flow_ref_elements_transform.htm&type=5 Attached is the screenshot.

Salesforce Fact #804 | Heap size in apex

The two methods of Limits class which show the details about the heap size: getHeapSize() and getLimitHeapSize(), the amount of memory is returned in bytes. Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_limits.htm

Salesforce Fact #803 | Add translations for standard country/state picklists

How to add the translation for the standard country and state picklist values? We can use Translation Workbench to add the translations. Steps: Setup -> Translate -> Choose the language -> In setup component, select Address Country or Address State -> Add the translations.

Salesforce Fact #802 | Child LWC to parent Aura using event propagation properties

Image
If we need to pass data from child LWC component to parent Aura which is two level away from the Aura component, we need to use bubbles: true and composed: true in the event payload. Attached are the code snippet screenshots.

Salesforce Fact #801 | Org wide email address error

Have you come across this error while sending out email from apex code? 'INSUFFICIENT_ACCESS_OR_READONLY, Not profiled to access this Org-wide Email Address' This error is encountered when the specified org wide email address is not enabled for the current user's profile. To check this, Go to Setup -> Organization-Wide Addresses -> Check if the profile is present under allowed profiles.