Spring 2019 Note: Pulsar now directly supports evaluating Salesforce formulas both online and offline.
By default, due to inherent processing limitations, formula field calculations are not persisted to the local database when offline.
This is often not a problem for organizations for various reasons. For many organizations, formula fields are only ever interacted with when on record detail pages (where these formulas are always dynamically calculated). Furthermore, formula field calculations are synced from Salesforce servers and persisted to the local database when online during record creation and updates, or when Pulsar next syncs those created/updated records. When online, there is always a readback that picks up server-side calculations.
But for some organizations, when running offline in Pulsar, the lack of persistence of formula field calculations can present a problem. This is usually due to the following two scenarios: (1) formula fields present in list views, and (2) customizations that directly query formula fields from the database (e.g. querying via PSL or via the Javascript API).
Luckily there is a mechanism from PSL to calculate and persist formula fields if you do encounter stale data problems.
DEFAULT{ Action=CalculateSaveFormulas; ObjectType=<ObjectAPIName>; ObjectIds=<Optional comma-separated list of object Ids. If empty/unspecified, will operate on all records of ObjectType>; WhereClause=<Optional WHERE clause to programmatically select specific Ids>; FormulaFields=<Optional comma-separated list of fields. If empty/unspecified, will operate on all formula fields of the ObjectType>; } |
For example, if you want to ensure that all formula fields on the Account object are always kept up-to-date in the local database, you may wish to create an OnSave PSL Validation Rule (see the next section in the wiki).
DEFAULT{ Action=CalculateSaveFormulas; ObjectType=Account; ObjectId=,; } |
Spring 2019 NOTE: we recommend that you use SFDC Formulas going forward, but PSL formulas will continue to be supported.
Pulsar originally did not support evaluating SFDC formulas, and instead offered similar functionality through logic implemented in Pulsar Settings Language (PSL).
PSL Formulas are implemented via a group of flexible Pulsar Settings that define the fields affected, the order in which they are processed, and the formula logic in PSL for each field. Just as in Salesforce formulas, default values are used during record creation and formula fields are used to calculate the proper values for fields throughout the life of the record.
Please note that regardless of the values calculated for formula fields in Pulsar, if the same field has a formula defined on Salesforce, the Salesforce formula supersedes the Pulsar formula when the record is synced to the server.
Formula fields and default value formulas follow an identical pattern when defined using Pulsar Settings. For each affected object or record type:
The formula field order and default value field order settings both allow you to specify a list of field API names separated by commas, newlines, or semicolons. The setting key optionally allows you to narrow the scope to a specific record type.
Name: Object Name – Formula Field Order
Key: pulsar.<object API name>[.<record type developer name>].formulaFieldOrder
Value: Field1APIName, Field2APIName, Field3APIName, ...
Example:
Name: Order Line Item – Formula Order
Key: pulsar.Order_Line_Item__c.formulaFieldOrder
Value: Unit_Price__c,Total_Discount__c,Amount__c
Name: Object Name – Default Value Field Order
Key: pulsar.<object API name>[.<record type developer name>].defaultValueFieldOrder
Value: Field1APIName,
Field2APIName,
Field3APIName,
...
Example:
Formula Settings
Defining the formulas associated with the default value or formula fields requires using PSL. The only requirement is to use the SetFieldInMemory action to set the resulting value to the field in question. The setting key optionally allows you to narrow the scope to a specific record type, as with the field order settings above.
Name: Object Name – Formula Field – Field Name
Key: pulsar.<object API name>[.<record type developer name>].<field API Name>.formula
Value: Pulsar Settings Language
Example:
Name: Order Line Item – Formula Fields – Unit Price
Key: pulsar.Order_Line_Item__c.Unit_Price__c.formula
Value: See the code below. Notice that the last action is the SetFIeldInMemory action.
DEFAULT{ Action=SetVar; VarName=UnitPrice; VarValue=Product__r.Unit_Price__c; | Action=SetFieldInMemory; FieldType=General; FieldName=Unit_Price__c; FieldValue=%%UnitPrice%%; } |
Name: Object Name – Default Value Field – Field Name
Key: pulsar.<object API name>[.<record type developer name>].<field API Name>.defaultvalue
Value: Pulsar Settings Language
Example:
Name: Cheque – Default Value Field – Cheque_Date__c
DEFAULT{ Action=SetVar; VarName=ThisDay; VarValue=@@Today; | Action=SetFieldInMemory; FieldType=General; FieldName=Cheque_Date__c; FieldValue=%%ThisDay%%; } |