How to implement Virtual Fields in XRL
Learn how to effectively implement virtual fields in your XRL database to streamline data processing and enhance reporting capabilities.
Introduction
The Add Virtual Field functionality in Orenda Grids allows users to dynamically create custom fields in a list view for specific use cases without modifying the underlying Salesforce object. These virtual fields enable calculations and data representations that are not stored in the database but are necessary for real-time analysis. This feature supports operations like sorting and filtering, making it as versatile as standard fields.
Virtual fields are created through the Configure dialog in Extended Related Lists (XRL) and are available only within the specific list view they are defined for.
Key Benefits of Virtual Fields Feature
- Perform on-the-fly calculations without altering the database schema.
- Extend list view capabilities to represent derived data for enhanced insights.
- Use advanced formatting and calculations through the formatter callback.
- Enable dynamic operations like sorting and filtering on calculated fields.
Prerequisite Make sure that you log in to your Salesforce account, install, and configure Orenda Grids XRL. Refer to the links below for more detailed instructions. Though virtual fields can be added in Grid by any user with XRL license, only a Power user can enable the field data using Advanced section in Field Settings. |
Limitations in Salesforce Views
While Salesforce provides robust data management capabilities, standard views have certain limitations that Orenda Grids’ Add Virtual Field feature addresses following limitations
1. Creating a new field in Salesforce requires administrative access and permanent schema changes. Standard users cannot add fields dynamically for temporary or specific use cases.
Procedure
Here, we will take an example use case: Calculating Total Price in a Custom Object to show how to create and use a virtual field in XRL.
Suppose your custom object contains two fields: List Price and Quantity, but no field for Total Price (calculated as List Price * Quantity
). Instead of creating a new field in Salesforce, you can use a virtual field to calculate and display the Total Price for each record dynamically.
Follow these steps to add a virtual field:
Step 1: Click on the Configure button at XRL home.
Step 2: Click on the Add Virtual Field tab within Field Selection Tab.
Step 3: Name the virtual field and put an api name as required and click on Save Virtual Field button.
Step 4: Now, proceed with Field Settings on the configuration wizard and select Total_Price field from the dropdown.
Step 5: Select Advanced Section as shown below and enter the code snippet mentioned below.
{
“formatter”: function(scope,libs,row,col,val){
return row.listPrice__c * row.quantity;
}
Step 6: Click on Save to save the current view with update or Save As to create a new view.
Results
The following procedure results in addition if a virtual field named Total_Price having value as per the conditions set in code.
By leveraging virtual fields, Salesforce users can extend the functionality of their list views to display calculated or derived data directly within the platform. This eliminates the need for manual data exports or schema changes, ensuring a streamlined and efficient workflow.