Posts

Showing posts with the label formula

Salesforce Fact #891 | Accessing custom metadata in screen flow formula

We can use Custom Metadata in flow entry criteria formula and also in formula resource. Here is the syntax:  {!$CustomMetadata.<Metadata api name>.<Record Name>.<Field api Name>} example: {!$CustomMetadata.Country__mdt.Brazil.Region__c}

Salesforce Fact #863 | Another POC using FormulaEvalInApex

Image
In order to fetch the currency conversion rate for a particular currency in Apex, we need to query CurrencyType or DatedConversionRate Sobject. We can make use of the FormulaEvalInApex feature to get the conversion rate using dynamic formula without the need of any SOQL. Attached is the screenshot.

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 #718 | CURRENCYRATE()

How to get the currency conversion rates in formula fields in a multi-currency org? We have a function called CURRENCYRATE() which can be used for this. It takes the CurrencyIsoCode as the input and returns the corresponding conversion rate with respect to the corporate currency. Reference:  https://help.salesforce.com/s/articleView?id=sf.customize_functions_currencyrate.htm&type=5

Salesforce Fact #580 | Check issandbox in validation rule and formula

Image
There is a field IsSandbox on Organization object which denotes whether the current org is a sandbox or not. But this field is not accessible using the $Organization global variable in formula field and validation rules. So, in order to check issandbox, we can create a custom metadata with a checkbox field and set it to true for sandboxes and keep it unchecked for non-sandbox orgs. Then we can refer this record in formula field and validation rules. Attached are the screenshots.