Drafted, not yet confirmed · your lab org
You'll take the training-discount prehook from the Apex pricing hooks page, which the setup deploys, put it into the quote procedure plan above pricing, and price one quote before and after it, so you see a hook change a price. Then you take it out again.
Your lab org comes with a sample company, QuantumBit. Its products, price books and billing setup are there because the labs use them, so leave them as they are. Everything a lab names starts with TGFG-, so you can always tell your work from QuantumBit's.
Before you start
To do this lab you need a lab org of your own, with this lab set up in it. This page lists what the lab needs, so you can set it up by hand. The lab kit does it for you. Start your own lab
Open your lab org with cci org browser my-lab, or from Org Launcher if you set it up. Track your orgs
You need a Revenue Cloud org built from Salesforce's launchpad with its QuantumBit sample catalog, and a user who can author Apex and edit procedure plans (Salesforce Pricing Design Time User or Procedure Plan Access). The launchpad's admin user already can.
This lab changes how training prices on quotes that also carry the Complete Solution, for everyone in the org, until you take the hook out in the last step. To change the plan you also switch it off for a minute or two, twice. Do it in a practice org.
The setup makes these for you:
| It makes | Called | What it's for |
|---|---|---|
| Two Apex classes at API version 68.0, deployed with their tests passing | QBTrainingDiscountHook and QBTrainingDiscountHookTest, from the Apex pricing hooks page | The hook you wire in |
| An account in USD, with one contact | TGFG-Hooks Lab | Someone to quote |
The lab also uses these from the QuantumBit sample, as they come:
| It uses | What it is |
|---|---|
| QuantumBit Essentials Training (QB-TRN-ESSNTLS) | The training line. 8,500 in the Standard Price Book in USD, selling model One-Time |
| QuantumBit Complete Solution (QB-COMPLETE) | A bundle, at 0 in four selling models. Its price comes from its components |
RLM_Quote_Pricing_Procedure_Plan |
The quote's procedure plan, Primary Object Quote, with three pricing procedure sections |
The setup doesn't touch the procedure plan: wiring the hook in is the lab.
To set up by hand instead, deploy the two classes from the Apex pricing hooks page and create the account and contact the table names.
Done this lab before? Run the setup again: it finds the account it made last time. Name the new quote TGFG-Hooks Lab Quote 2. If the procedure plan still has a TGFG_TrainingPreHook section, skip the step that adds it and go on to the one that moves it.
Every step of this lab has been clicked through on screen in a fresh lab org.
Steps
Find the hook class
Apex codeWhy A hook is an ordinary Apex class that implements the
RevSignaling.SignalingApexProcessorinterface. The procedure plan will call it by its class name.Go to Setup then Quick Find then
Apex Classesthen Apex Classes then QBTrainingDiscountHookSetup opens in a new browser tab. The Apex Classes list is a classic page. Check the Api Version and Status columns, then click the class name.
You should see: QBTrainingDiscountHook and, on the next row, QBTrainingDiscountHookTest, both with Api Version 68.0 and Status Active. The class's page, Apex Class Detail, starts with "global class QBTrainingDiscountHook implements
RevSignaling.SignalingApexProcessor". Its Code Coverage can read 0% (0/55) even though the tests passed when the setup deployed it.Check Revenue Settings
SetupWhy A procedure plan, and the hooks in it, drive pricing only when Procedure Plan Orchestration for Pricing is on. Salesforce's help also says to leave Exclude Default and Sales Transaction Type Pricing Procedures off.
Go to Setup then Quick Find then
Revenue Settingsthen Revenue SettingsBoth settings are near the bottom of the page. If orchestration is off, turn it on. Leave the other one off.
You should see: Procedure Plan Orchestration for Pricing Enabled, and "Exclude Default and Sales Transaction Type Pricing Procedures." Disabled.
Create the lab quote
QuoteWhy You price this one quote before and after the hook goes in, so the hook is the only thing that changes.
Go to App Launcher then
Quotesthen Quotes then New QuoteField Set it to Why Quote Name TGFG-Hooks Lab QuoteThe TGFG- start keeps it apart from QuantumBit's records. Second time through, use TGFG-Hooks Lab Quote 2.Account for Quote Search TGFG-Hooksand pick TGFG-Hooks LabThe account the setup made. Status Draft, as it comes A new quote starts as a draft. Quote Currency USD - U.S. Dollar, as it comes The training price this lab uses is the USD entry. Click Save.
You should see: the quote's page, TGFG-Hooks Lab Quote, open on its Quote Lines tab with the path on Draft, Quote Line Items (0) and Grand Total USD 0.00.
Price training on its own
Quote Line ItemWhy This is the price without the hook. The rule needs the Complete Solution on the same quote, so it couldn't fire here even with the hook in.
Go to App Launcher then
Quotesthen Quotes then TGFG-Hooks Lab Quote then Quote Lines then Add ProductThe search is the "Add Product" box in the shaded first row of the Quote Line Items grid. If it isn't open, double-click that row's Product ID cell. Type
QuantumBit Essentials Trainingand press Enter: it searches only on Enter. The first time, a Choose Price Book window opens with Standard Price Book already picked: click Save. Salesforce's help says a rep creating a quote first selects the price book, and each product's price comes from it. The box is empty after that, so double-click the Product ID cell, type the name again and press Enter. Pick QuantumBit Essentials Training (QuantumBit Software, USD 8,500.00), then click Save under the grid. Then point at the line's Net Unit Price.You should see: one line, QuantumBit Essentials Training, quantity 1.00, with List Price, Sales Price and Net Unit Price USD 8,500.00 and nothing under Adjustment Type. Grand Total is USD 8,500.00. Pointing at the Net Unit Price opens Calculation Details: "Get base prices from price book" USD 8,500.00, "Get unit cost from cost book", and Net Unit Price USD 8,500.00, with no discount row.
Add the hook to the plan
SetupWhy A hook isn't a trigger. It's a section of the procedure plan with Section Type Apex, and the plan runs its sections in order, in one Apex transaction.
Go to Setup then Quick Find then
Procedure Plan Definitionsthen Procedure Plan Definitions thenRLM_Quote_Pricing_Procedure_Planthen Deactivate then AddWhile the plan is Active, Add and Manage Sections are greyed out, so click Deactivate first and OK in "Deactivate the procedure plan definition?". Salesforce warns there that anything using the plan can fail while it's inactive, so do this step and the next without a break. Then click Add in Procedure Plan Sections, leave Standard selected, fill Name and Section Type, and click Save in the window. Expand the new section with its arrow and set the last three. Apex appears once Resolution Type is set: type the class name and pick it from the list. Then click Save at the top of the page.
Field Set it to Why Name TGFG_TrainingPreHookThe name you'll find it by when you move it, and when you take it out. Section Type Apex The section runs an Apex class instead of a pricing procedure. Phases Pricing The hook runs as part of pricing. Resolution Type Default The setting Salesforce's help gives for an Apex hook. Apex QBTrainingDiscountHookThe class the section calls. You should see: "Procedure Plan Definition
RLM_Quote_Pricing_Procedure_Planwas updated.", Status Inactive, and Procedure Plan Sections (4) withTGFG_TrainingPreHookfourth and Apex under its name.Move it above pricing
SetupWhy A section above the pricing sections runs before pricing, which makes it a prehook. Below them it would be a posthook, too late to change the discount pricing uses.
Go to
RLM_Quote_Pricing_Procedure_Planthen Procedure Plan Sections then Manage SectionsIn the Manage Sections window, drag
TGFG_TrainingPreHookby its handle to the top, aboveDefaultPricing, the first of the plan's three pricing procedure sections. Click Save in the window, then Save at the top of the page, then Activate.You should see:
TGFG_TrainingPreHookfirst, thenDefaultPricing, IFPartnerDistributorOnQuote andHeaderDistribution, and the message "Activation can take several minutes to complete. When the definition is activated, the status changes to Active." The open page keeps saying Inactive. Go back to Procedure Plan Definitions after a minute or so: the plan's Status there is Active.Price it with the Complete Solution
Quote Line ItemWhy Now the quote carries the line the rule looks for. Saving runs the plan, so the hook should write a 10 percent discount onto the training line before the pricing sections price it.
Go to App Launcher then
Quotesthen Quotes then TGFG-Hooks Lab Quote then Browse Catalogs then BundleThe Complete Solution comes in four selling models, so add it from the catalog, where you can pick one. Beside QuantumBit Complete Solution's price, USD 0, click the small icon to open its Buying options. Choose "USD 0 for
TermDefinedAnnual", click Add, then Save Quote. Then point at the training line's Net Unit Price.You should see: Quote Line Items (6). The training line shows Adjustment Type 10.00% and a Net Unit Price of USD 7,650.00, which is 8,500 less 10 percent. Its Calculation Details has a new row, "Calculate net unit and item net total prices after percentage-based discount", 10.00% and -USD 850.00. The Complete Solution sits at USD 0.00 with its four components under it at their own prices, none of them discounted. Grand Total is USD 98,650.00.
Take the Complete Solution off
Quote Line ItemWhy The hook only sets the discount; it never takes it away. This is the first item in the topic page's Watch out section, seen on a real quote.
Go to App Launcher then
Quotesthen Quotes then TGFG-Hooks Lab Quote then Quote LinesOpen the arrow menu at the end of the QuantumBit Complete Solution row and choose Delete, then Delete in "Delete Quote Line Item". Its components go with it. Click Save under the grid.
You should see: Quote Line Items (1), and the training line still at Adjustment Type 10.00% and a Net Unit Price of USD 7,650.00. Grand Total is USD 7,650.00. With the Complete Solution gone the hook writes nothing, so the discount saved on the line stays.
Take the hook out
SetupWhy While the hook is in the plan it changes training prices on quotes for everyone in the org.
Go to Setup then Quick Find then
Procedure Plan Definitionsthen Procedure Plan Definitions thenRLM_Quote_Pricing_Procedure_PlanClick Deactivate and OK. Click the bin button on the
TGFG_TrainingPreHookrow and OK in "Delete Procedure Plan Section?". Click Save, then Activate. If you turned on Procedure Plan Orchestration for Pricing in Revenue Settings, turn it off again.You should see: "Procedure Plan Definition
RLM_Quote_Pricing_Procedure_Planwas activated.", Status Active, and Procedure Plan Sections (3):DefaultPricing, IFPartnerDistributorOnQuote andHeaderDistribution. New quotes price training at 8,500 again, with the Complete Solution or without it. Quotes you already priced keep the discount until a rep changes it: Reprice All on TGFG-Hooks Lab Quote still shows 10.00% and USD 7,650.00.
What to take away
A hook is a section in the procedure plan, not a trigger. It runs on every pricing change, reads and writes the pricing context, and never writes records. Keep the rule in plain Apex that a unit test can reach, read only the tags you need, and decide on purpose what happens when the condition that set a value goes away.
The reasons in each step come from Salesforce's documentation and from what we checked in a Revenue Cloud org. The guide pages list the sources: Apex pricing hooks and Quote.