# Demo formula reference

Synthetic Developer Edition configuration from October 15, 2026. Reference text only: no deployable metadata, Apex or Flow is included. Do not deploy without adapting permissions, validation, input constraints and commitment paths.

## Authorization_State__c

```text
Field: Authorization_State__c   Type: Formula (Text)
Description: Live authorization. An approval covers discount, list price and delivery cost exactly; any change invalidates it.

IF(Discount_Pct__c <= 0.10, "WITHIN SELLER AUTHORITY",
 IF(ISPICKVAL(Approval_Status__c, "Pending"), "PENDING APPROVAL",
  IF(ISPICKVAL(Approval_Status__c, "Rejected"), "REJECTED",
   IF(NOT(ISPICKVAL(Approval_Status__c, "Approved")), "APPROVAL REQUIRED",
    IF(AND(Discount_Pct__c = Approved_Discount_Pct__c,
           List_Price__c = Approved_List_Price__c,
           Delivery_Cost__c = Approved_Delivery_Cost__c),
       "AUTHORIZED - TERMS MATCH APPROVAL",
       "INVALIDATED - TERMS CHANGED SINCE APPROVAL")))))
```

## Gross_Margin_Pct__c

```text
Field: Gross_Margin_Pct__c   Type: Formula (Percent, 2 dp)
IF(Net_Selling_Price__c = 0, NULL, (Net_Selling_Price__c - Delivery_Cost__c) / Net_Selling_Price__c)
```

## Gross_Profit__c

```text
Field: Gross_Profit__c   Type: Formula (Currency, 2 dp)
Net_Selling_Price__c - Delivery_Cost__c
```

## Net_Selling_Price__c

```text
Field: Net_Selling_Price__c   Type: Formula (Currency, 2 dp)
List_Price__c * (1 - Discount_Pct__c)
```

## Approval_Fields_Set_Only_By_Process

```text
Validation rule: Approval_Fields_Set_Only_By_Process   (Active)

Error condition formula:
OR(
  AND(ISNEW(),
      OR(NOT(ISPICKVAL(Approval_Status__c, "Not Submitted")),
         NOT(ISBLANK(Approved_Discount_Pct__c)))),
  AND(NOT(ISNEW()),
      OR(ISCHANGED(Approval_Status__c),
         ISCHANGED(Approved_Discount_Pct__c)))
)
Error message:
Approval Status and Approved Discount can only be set by the approval process. Use Submit for Approval.

Why it works: approval-process field updates do not re-run validation rules, so the process can still write these fields (verified in tests T9 and T10).
Known gap: Approved_List_Price__c and Approved_Delivery_Cost__c (added in phase 3) are NOT covered by this rule. They are protected only by read-only FLS for non-admins.
```

## Release_Requires_Valid_Discount_Approval

```text
Validation rule: Release_Requires_Valid_Discount_Approval   (Active)

CURRENT VERSION (phase 3)
Error condition formula:
AND(
  Released__c,
  NOT(OR(
    Authorization_State__c = "WITHIN SELLER AUTHORITY",
    Authorization_State__c = "AUTHORIZED - TERMS MATCH APPROVAL"
  ))
)
Error message:
Release blocked: this discount is not currently authorized. Discounts above 10% need approval, and any change to discount, list price or delivery cost after approval invalidates it. Submit for approval again.

SUPERSEDED VERSION (phases 1-2, kept for reference)
AND(
  Released__c,
  Discount_Pct__c > 0.10,
  OR(
    NOT(ISPICKVAL(Approval_Status__c, "Approved")),
    ISBLANK(Approved_Discount_Pct__c),
    Discount_Pct__c > Approved_Discount_Pct__c
  )
)
Message: Release blocked: discounts above 10% need manager approval, and the current discount cannot exceed the approved discount. Submit (or resubmit) for approval.
Weakness that phase 3 fixed: it compared only the discount and only upward; list price and delivery cost changes went undetected.
```

## Coverage limits

Only discount increases were exercised after approval. List-price/cost changes and discount decreases follow from formula inspection. The seller-authority branch takes precedence at or below 10%. Approved list-price and cost snapshots are absent from the process-only validation rule. See the article for production gaps.
