Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 21 Next »

Salesforce Formulas

Pulsar directly supports evaluating Salesforce formulas both online and offline.

  • Supports formula fields
  • Supports default value field formulas (during initial record creation)
  • All numeric, logical, string, and date/time operators and functions are supported
  • Most summary and advanced functions are supported (some server-side-specific functions are not supported)
  • Set pulsar.formula.enableSFDCFormulas Pulsar Setting to TRUE to enable this functionality in the Pulsar mobile app

Best practices and caveats

  • If there is both a Salesforce formula and a Pulsar Settings Langugae (PSL) formula (see below) for the same field, the PSL formula takes precedence, and the Salesforce formula is ignored
  • Salesforce formulas and PSL formulas across objects/fields should not interact (e.g., if FormulaFieldA__c is a Salesforce formula and FormulaFieldB__c is a PSL formula, the result is undefined if they reference each other).
  • Formula fields are calculated on-the-fly every time you view a record detail page (but not when editing)
  • Currently due to processing limitations, formula fields are NOT calculated in list views.  Stale values may be shown in list views unless steps are taken to persist calculations (see below).

Offline persistence of formula field calculations

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, user interactions with formula fields are usually only 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 offline created/updated records.  When online or syncing 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 usually happens in 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 shown here (as well as the Javascript API) to calculate and persist formula fields to explicitly avoid 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>;
}

Let's say, for example, you want to ensure that all formula fields on the Account object are always kept up-to-date in the local database.  You can create an OnSave PSL Trigger (see the next section in the wiki about PSL Validation Rules and Triggers).  The following example PSL will accomplish that:

DEFAULT{
Action=SetVar;
VarName=Account_Id;
VarValue=@@CurrentObjectId@@;
| 
Action=CalculateSaveFormulas;
ObjectType=Account;
ObjectIds=%%Account_Id%%;
}

WARNING: this can be an incredibly expensive operation if you do not specify any filter criteria.  In the example above, had we not specified the ObjectIds parameter, then the calculation and persistence would run on all Account records!

  • No labels