Revenue Cloud project notebook, written by two Meir IT consultants who implement it.

What is Revenue Cloud?

Quote and Order·Admin

Revenue Cloud Discount Approval with a Flow Approval Process

Locking a quote above a 20% discount, natively: the trigger and its filters, calculating the discount with context attributes, the components to add, and the rollout incident.

Nathan Altmann · Revenue Cloud consultant at Meir IT

Published 8 min read

In 3 linesfor leadership

  1. A discount approval process was running, but nobody saw the requests and approving changed nothing.
  2. The native process only locks and logs; which quotes enter, and what follows a decision, must be built.
  3. Quotes above a 20% discount now lock until approved, using native tools and no extra field on the quote.
In this article (12 sections)
  1. The first version and its three flaws
  2. The right flow type
  3. The trigger and its three filters
  4. Which discount field to read
  5. Calculating the discount without a custom field
  6. The approval step
  7. The UI and permissions
  8. The rollout incident
  9. Other traps
  10. Rollout order
  11. What's still open
  12. In practice

Stage: the quote, between pricing and sending it to the customer. The client wanted a quote to lock above a 20% discount and wait for approval. A first version existed and was running: it had no threshold, nobody could see the requests, and approving changed nothing. It was rebuilt natively, with a Flow Approval Process and no custom field on the quote.

The first version and its three flaws

The process was a Flow Approval Process, the newer framework built on Flow Orchestration, not the old Approval Process in Setup. But:

  • it was launched manually, with no entry condition. A quote with a 0% discount had gone to approval;
  • no Lightning page in the org held an approval component. The two submitted requests had been waiting for three weeks;
  • the approval step led straight to the end of the flow. The decision was captured, then nothing read it.

On top of that, there was an active clone of the same flow, and the sales profiles had no access to the approval objects.

All three flaws come from the same place: a Flow Approval Process gives you the lock and the record of the decision, and nothing around them. Which quotes go in, where the approver sees the request, what happens after the decision: all of that is still yours to build. The flow can be active and do nothing useful.

The right flow type

A Flow Approval Process is a flow whose processType is ApprovalWorkflow. It locks the record, records the decision and deploys like any other flow. The type is set at creation: a record-triggered flow can't be converted later.

The trigger and its three filters

The process was rebuilt as an after-save flow on quote update:

Process triggerFlow XML
<processType>ApprovalWorkflow</processType>
<start>
    <object>Quote</object>
    <recordTriggerType>Update</recordTriggerType>
    <triggerType>RecordAfterSave</triggerType>
    <doesRequireRecordChangedToMeetCriteria>true</doesRequireRecordChangedToMeetCriteria>
    <filterLogic>and</filterLogic>
    <filters>
        <field>AppliedDiscount</field>
        <operator>GreaterThanOrEqualTo</operator>
        <value><numberValue>20.0</numberValue></value>
    </filters>
    <filters>
        <field>CalculationStatus</field>
        <operator>EqualTo</operator>
        <value><stringValue>CompletedWithPricing</stringValue></value>
    </filters>
    <filters>
        <field>LastModifiedById</field>
        <operator>EqualTo</operator>
        <value><stringValue>005XXXXXXXXXXXXXXX</stringValue></value>
    </filters>
</start>

doesRequireRecordChangedToMeetCriteria set to true. Without it, every new save of a 30% quote fires another request. With it, the request goes out once, when the quote crosses the threshold.

CalculationStatus equals CompletedWithPricing. During recalculation, a Revenue Cloud quote goes through intermediate states. Firing before pricing finishes means reading a provisional discount.

The LastModifiedById filter. It limits the process to quotes edited by one user during rollout. That filter is what contained the incident described below. Remove it afterwards, or the process only protects one person.

Which discount field to read

On a Revenue Cloud quote, several fields look like "the discount." Here's what this project showed:

FieldFinding
AppliedDiscountUsed. The quote's overall discount percentage, writable.
DiscountNot updatable, even though many profiles have edit access to it.
TotalAdjustmentAmountStayed at 0, even with lines discounted 90%.
Line ListPriceDiffered from the actual calculated price on some lines.

According to the Quote object reference, AppliedDiscount is the overall discount entered on the quote and then distributed across the lines. Discounts set line by line don't fill it on their own. On this project, the pricing procedure calculates the discount and writes it to that field in its last step. So the threshold reads a calculated value, and that's what makes it reliable.

Calculating the discount without a custom field

The discount that matters is the gap between the net price before and after manual discounts, weighted by quantity:

discount = 1 − Σ (quantity × net price) / Σ (quantity × price before manual discount)

The usual reflex is a custom field on the line, filled by a trigger. I went with transient context attributes instead: attributes of the sales transaction context that exist during the calculation and are never saved to the database.

Transient attributeContext Definition XML
<contextAttributes>
    <title>BaseNetUnitBeforeManualDiscount</title>
    <dataType>currency</dataType>
    <fieldType>inputoutput</fieldType>
    <transient>true</transient>
</contextAttributes>

A describe of the quote line won't find them, and that's expected. The pricing procedure uses them in four steps:

  1. capture the net unit price before manual discounts;
  2. calculate each line's discount amount: quantity × (captured price − net price);
  3. add those amounts up at quote level;
  4. divide by the total before discount, and write the percentage to AppliedDiscount.

Three constraints of pricing procedure formulas that came up on this project:

  • a division by zero fails the whole calculation, so always write a / IF ( b > 0 , b , 1 );
  • the editor rejected MAX, MIN and OR. A floor is written with nested IFs;
  • an aggregate can only write to an attribute that exists in the context definition. Otherwise the deployment fails with a message like valid data type for section-0-output. After adding it, reload the editor to see the new attribute.

The approval step

Approval stepFlow XML
<stageSteps>
    <name>Valider_la_remise</name>
    <actionName>standard_approvals__ReviewAppvlRqst</actionName>
    <actionType>stepApproval</actionType>
    <stepSubtype>ApprovalStep</stepSubtype>
    <assignees>
        <assignee><elementReference>firstApprover</elementReference></assignee>
        <assigneeType>Resource</assigneeType>
    </assignees>
    <canAssigneeEdit>true</canAssigneeEdit>
    <shouldLock>true</shouldLock>
    <inputParameters>
        <name>ActionInput__RecordId</name>
        <value><elementReference>$Record.Id</elementReference></value>
    </inputParameters>
    <inputParameters>
        <name>approvalInformation</name>
        <value><elementReference>InfoDemande</elementReference></value>
    </inputParameters>
</stageSteps>

standard_approvals__ReviewAppvlRqst is the standard action that creates the work item. Other actions have similar names; this is the one you want.

shouldLock set to true locks the quote while it waits.

canAssigneeEdit set to true lets the approver edit the quote before approving, say bringing 35% down to 25%, without a rejection and a new cycle.

assigneeType set to Resource names the approver through a flow variable. That variable expects a username, not an Id, which explains the incident below.

The approvalInformation parameter is the text the approver sees in the request. A formula is enough:

Text the approver seesFormula
"Quote: " & {!$Record.Name}
  & " | Overall discount: " & TEXT({!$Record.AppliedDiscount}) & "%"
  & " | Amount: " & TEXT({!$Record.TotalPrice}) & " USD"

With that information, the approver doesn't need to open the quote to decide. The field is TotalPrice: TotalAmount doesn't exist on Quote.

Before the approval, a background step calls a subflow that sends a Salesforce notification (the Send Custom Notification action, with a notification type created in Notification Builder). The email already goes out on its own; the notification also shows up in the bell and on mobile.

Finally, the approvalDecision and approvalComments outputs feed the rest of the flow: notify the rep, or set the quote back to draft after a rejection. In the first version, nothing read them.

The UI and permissions

An active Flow Approval Process adds no component to the record page. You place two in Lightning App Builder:

  • Request Approvals, for the rep: request status and submission;
  • Orchestration Work Guide, for the approver: Approve, Reject and the comment.

I couldn't find their API names in the help or the Metadata API reference. So they were placed by hand, and the page was then retrieved as metadata.

Approvers also need read access to ApprovalSubmission, ApprovalWorkItem and ApprovalSubmissionDetail, plus the Access Orchestration Objects permission. No sales profile had them, so they went into a dedicated permission set.

The rollout incident

On the first save in production, the save failed with An unhandled fault has occurred in this flow.

The approver variable held the sandbox username. A refresh keeps Ids but adds a suffix to usernames. In production, that username didn't exist, so the step couldn't find the approver. And because the flow runs after save, the quote save itself failed. The single-user filter kept the incident to that one person.

The immediate fix was the right username. The lasting fix is to look the approver up dynamically, by role or manager, instead of hard-coding it in the flow.

Other traps

SymptomCause
The lock doesn't seem to workThe test runs as an admin, whose permissions override the lock. Test with a sales profile.
Several requests for the same quotedoesRequireRecordChangedToMeetCriteria set to false.
A request fires on a provisional priceNo filter on CalculationStatus.
The retrieved flow doesn't show the fixA flow retrieve returns the latest version, not necessarily the active one.

To see which version runs, compare the active version with the latest one:

Active and latest versionsf CLI
sf data query -o <org> \
  -q "SELECT DeveloperName, ActiveVersionId, LatestVersionId FROM FlowDefinitionView \
      WHERE ApiName = '<nom_du_flow>'"

Rollout order

  1. The pricing procedure, at a quiet time: it affects every quote. Before activating it, reprice an existing quote and check that its amount doesn't move.
  2. The notification subflow.
  3. The approval process, filtered to one user.
  4. The full test, with a sales profile: threshold crossed, notification, lock, approval, unlock.
  5. Removing the user filter.

To roll back, deactivating the flow is enough: quotes save again right away, and requests already open can still be processed. On the pricing side, the previous procedure version is kept inactive rather than deleted.

What's still open

The procedure writes the calculated discount to AppliedDiscount, a field Revenue Cloud can also read as an overall discount to distribute across the lines. I haven't yet proven that a later reprice never applies it a second time. The test: reprice the same discounted quote several times and check that net prices don't move.

In practice

  • Filter the trigger on CalculationStatus equals CompletedWithPricing, and set doesRequireRecordChangedToMeetCriteria to true.
  • Check where the discount field your threshold reads gets its value: on this project, from the last step of the pricing procedure.
  • Place Request Approvals and Orchestration Work Guide on the quote page, and grant access to the approval objects in a permission set.
  • Wire approvalDecision and approvalComments into the rest of the flow.
  • Name the approver with a username that exists in the target org, or better, by role or manager.
  • Turn it on for one user first, and test with a sales profile.

The business side (picking the threshold and the approver, and what the team goes through) is in the business version of this article. For a discount typed straight into the sales price, which the threshold doesn't see, see typed sales price vs. discount.

A technical question about this article?

A question about this article? I reply within 48 hours.

Something unclear, a mistake, or different behavior in your Salesforce org? Write to me.

Prefer email? Write to nathan@meir-it.com

Get notified of new articles

Type at least two letters.