Posts

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