Formulas

A formula is a standard Salesforce formula expression that ContextWorks evaluates against the loaded record. It produces a value the object doesn’t store.

Use one when the number an agent should quote isn’t a field — weighted pipeline, days until renewal, margin — or when a field holds it but the value is stale or missing. No schema change, no deployment.


How it works

Formulas read fields already in memory, so they cost no query. That’s why they default to list level, and why a formula beats a metric whenever both could produce the number.

Define one

Studio → Formulas → New Formula

SettingExample
LabelWeighted Amount
API nameweighted_amount — generated from the label, fixed after creation
ExpressionAmount * Probability
Return typeCurrency
InstructionAmount × probability. Not the same as Expected Revenue, which is set manually.

Formulas use the same four element tabs — Details, Definition, Available For, Where Used. → Elements

Add it to an entity

A formula runs only on entities that use it. Two ways to add one:

  • The element’s Where Used tab
  • + Add Formula on an entity’s canvas, under Core Record

If the canvas dropdown shows no available formulas, every applicable one is already added or none apply to this object — check Available For. In the payload, formulas render alongside metrics under Summary Metrics.

Write the expression

Write standard Salesforce formula syntax:

Amount * Probability
(Amount - Cost__c) / Amount
CloseDate - TODAY()
IF(IsClosed, "Closed", "Open")

ContextWorks adds every field the expression names to the query, so Amount * Probability works even if you never curate Probability. That field reaches the payload only if you curate it too.

WARNING

Percent fields evaluate as fractions: 100% is 1.0, not 100. Amount * Probability gives the weighted amount directly — no / 100. This is the most common formula mistake.

Set the return type

Number, Currency, Percent, Text, Boolean, Date, or Date/Time. The return type drives rendering: a currency gets its symbol, a date gets formatted. Set it correctly even when the arithmetic doesn’t care.

Restrict Available For

An expression works only on objects that have its fields: Amount * Probability works on Opportunity and nowhere else. Name those objects under Available For.

Formula field or ContextWorks formula?

If the org already has a formula field on the object, curate it as a field. A formula field is queryable, and reports can use it too.

Use a ContextWorks formula when only agent context needs the value, when you can’t or don’t want to add a field to the object, or when the number is specific to how agents should read the record.

Best practices

An expression that can’t resolve its fields fails at render: the agent gets no value and no warning. Naming the objects up front turns that into a configuration error you can see.

Error handling

An expression that can’t evaluate — missing field, type mismatch, division by zero — doesn’t break the payload. ContextWorks drops the formula and records a structured issue on Issues. The agent sees no error, so check the Issues page after adding one.

What’s next