Evolve Forms allows administrators and developers to dynamically calculate any value to be rendered on the screen as if it were an actual field using Apex or Flow.
This is far more robust than normal formula fields. Calculated Fields enables rendering data calculated from child records or the result of a callout, and it does not consume any columns in the schema.
If you can compute it in Apex or Flow, then you can render it on the screen as if it were a field.
The fields will be calculated using a Renderer. A renderer will accept the current record's Id as input and return a collection of CalculatedField
objects.
The CalculatedField
class has public @AuraEnabled
variables whose data types correspond to the public properties of the lightning-formatted-XYZ
Lightning Web Component.
The values in the populated data type will be rendered on the screen as if it were a field on the record, using all of the formatting capabilities of the corresponding Lightning Web Component.
To define a flow-based renderer, create an autolaunched flow with the following variable specifications:
Variable Name | Variable Type | Available for Input | Available for Output | Description |
---|---|---|---|---|
recordId |
text | yes | no | The Id of the record |
calculatedFields |
Collection of CalculatedField |
no | yes | The calculated fields to be rendered on the screen |
Then, add the Calculated Fields Section
component to your record page and provide the flow's API name.
Apex renderers work very similarly to flow renderers. Create a class which implements the CalculatedFieldController.Renderer
interface:
public class ContactCalculatedFields implements CalculatedFieldController.Renderer {
public List<CalculatedField> getFields(Id recordId) {
List<CalculatedField> result = new List<CalculatedField>();
List<Contact> contacts = [
SELECT Account.Parent.Name
FROM Contact
WHERE Id = :recordId
];
String parentAccountName = contacts?.get(0)?.Account?.Parent?.Name;
if (parentAccountName == null) {
return result;
}
CalculatedField field = new CalculatedField();
field.label = 'Account\'s Parent Account Name';
field.text = new LightningFormattedText();
field.text.value = parentAccountName;
result.add(field);
return result;
}
}
Then, add the Calculated Fields Section
component to your record page and provide the Apex class name.