Posts

Showing posts from July, 2024

Salesforce Fact #862 | POC with FormulaEvalInApex

Image
The FormulaEvalInApex feature is in developer preview. We can construct dynamic formula in apex using this feature. In this example, we have constructed a formula to return the day of week for an input date. Reference:  https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_formulaeval.htm&release=248&type=5 Attached are the screenshots.

Salesforce Fact #861 | Simplified null check in string contains function

Image
Sometimes we may encounter NullPointerException while dealing with the contains() string function. The null check can be simplified using the new Null Coalescing operator. Attached are the screenshots.

Salesforce Fact #860 | Remove noreply@salesforce.com from email sender address

Sometimes in the emails sent from Salesforce, noreply@salesforce.com is added automatically. This can be controlled from an email deliverability setting. Setup -> Email -> Deliverability -> Email Security Compliance section -> Uncheck the 'Enable Sender ID compliance' checkbox. Reference:  https://help.salesforce.com/s/articleView?id=000383125&type=1

Salesforce Fact #859 | NetworkId error in ContentVersion record in test class

Have you encountered the error in test class: You do not have the level of access to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary: [NetworkId] This error is encountered while trying to insert a ContentVersion record. The insert fails because the NetworkId field is not set. To resolve this, query the NetworkId from the network Sobject using the below SOQL and set the same in the ContentVersion record before insert: Id networkId = [SELECT Id FROM Network LIMIT 1].Id; Reference:  https://salesforce.stackexchange.com/questions/325997/insufficient-access-on-cross-reference-entity-networkid

Salesforce Fact #858 | Polymorphic SOQL on ContentDocumentLink

Image
This is how we can use a polymorphic SOQL on ContentDocumentLink LinkedEntity field. Ideally the fields which can be selected comes from a Name Sobject which is relevant when dealing with polymorphic relationship queries. Reference:  https://developer.salesforce.com/docs/atlas.en-us.238.0.object_reference.meta/object_reference/sforce_api_objects_name.htm?_ga=2.114364804.2097756510.1721467571-1754518336.1719649716 Attached is the screenshot.

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 #856 | BatchApexErrorEvent subscribe using flow

BatchApexErrorEvent  is a built in event which is triggered for unhandled exception in batch class. In order to raise platform events from batch apex, we need to implement Database.RaisesPlatformEvents interface. We can subscribe to BatchApexErrorEvents using platform event type triggered flow. Reference:  https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/sforce_api_objects_batchapexerrorevent.htm

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.

Salesforce Fact #854 | recalculateFormulas() count towards SOQL query count

Image
We have the recalculateFormulas() function of Formula class which can evaluate the formula without saving the sobject record and this is super helpful in test classes. An interesting thing is, when the sobject record contains all the fields which are needed for the formula evaluation, then Formula.recalculateFormulas() does not count towards the total SOQL query count. But, if the sobject record does not have any of the field which is needed for the formula evaluation, the recalculateFormulas() call is counted as 1 SOQL query. In this example, we have two number fields, Test_Runs and ODI_Runs and a formula field, Total_Runs which is the sum of ODI and Test runs. Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Formula.htm#apex_System_Formula_recalculateFormulas Attached are the screenshots.

Salesforce Fact #853 | Sobject update fact

Image
In apex, if we add an sobject record to a list and then update any of the field value the final list would include that value. But that's not the case in case of flow. In this example, we are adding an account record to a list and then updating the rating to 'Cold'. After DML is made on the list, the account rating would be 'Cold'. In case of flow, it doesn't update the rating. Note: As a best practice, always make the necessary updates to sobject record and finally add to the list. The above example is only for demonstration purpose and should not be followed.

Salesforce Fact #852 | Preview and Non-preview sandbox

There are two types of sandboxes in terms of Salesforce release: Preview sandbox and Non-Preview sandbox. A preview sandbox provides early access to new features before the production upgrade. These sandboxes are upgraded automatically approximately 6 weeks before the production release. A non-preview sandbox is not upgraded early and is ideally upgraded after the production release. To check the release type of the sandbox, go to production org -> setup -> search for Sandboxes in quick search -> check the release type of the sandboxes. Reference:  https://help.salesforce.com/s/articleView?id=sf.data_sandbox_preview.htm&type=5