Agentforce Revenue Cloud : Apex Pre/Post Hooks & Test Coverage Class

In Salesforce Revenue Cloud, a Procedure Plan orchestrates the end-to-end execution of pricing and validation steps within a transaction. Pre Hooks modify or validate inputs before a step runs, while Post Hooks adjust outputs or trigger follow-up logic after it completes.

"MD" - Maruthi Dronamraju

1. Introduction

Procedure Plan in Salesforce Revenue Cloud is a configuration framework that lets you orchestrate and sequence multiple pricing procedures (and potentially other types of procedures) in a flexible, conditional way.

A Procedure Plan Definition combines individual procedures into a single, unified plan. You can arrange them in any order, add branching logic based on conditions, and define when each one should run, tailored to your business requirements like different transaction types (e.g., new sale, amendment, renewal, or cancellation).

It acts as a centralized "orchestrator" or routing system: it doesn't contain the actual pricing calculation logic itself (that's in the Pricing Procedures), but it controls which procedures execute, in what sequence, and under what conditions during processes like quote or order pricing.

Apex Pre/Post Hooks are directly tied to Procedure Plans as extension points that let you inject custom logic before or after a specific step as the procedure plan executes.

3.1 Apex Prehook Class

Make sure your Apex Prehook class is set to API version 64.0 or higher, as the RevSignaling namespace is only available starting in version 64. Without updating the class version, the RevSignaling interfaces and related types won’t be accessible during compilation.

Remember that data from the Context Instance is accessed using Tag Names, whereas any updates to the Context must be performed using the corresponding Attribute Names. Understanding this distinction is key to correctly reading from and writing back to the pricing context in your Pre and Post Hooks.

In conclusion, Apex Pre and Post Hooks provide powerful extension points to tailor the pricing lifecycle to your specific business needs. Prehooks allow you to shape and enrich the pricing context before the engine executes, such as injecting dynamic discounts or adjusting inputs, while Posthooks enable you to react to computed results, perform validations, or apply additional adjustments after pricing is complete. Together, they offer a clean, governed way to extend standard behavior without disrupting core logic.

4. Conclusion
2. Procedure Plan Setup
2.1 Enable Procedure Plan
3. Apex Prehook Sample
  1. Navigate to Setup > Revenue Settings and enable Procedure Plan Orchestration for Pricing.

  2. Navigate to Setup > Revenue Settings, toggle on Exclude Default and Sales Transaction Type Pricing Procedures

Let’s build a simple Apex Pre Hook for the Standard Quote process in Revenue Cloud. This Apex Prehook will automatically apply a random discount (between 5% - 15%) to all quote lines added to the quote before pricing completes.

Finally, we’ll write a corresponding Apex test class to validate the logic and ensure the discount is applied correctly.

3.2 Apex Prehook Test Class

Ensure your Apex Prehook class is set to API version 64.0 or higher, since the RevSignaling namespace is available only starting from version 64; otherwise, the related interfaces and types won’t compile. For simplicity, this example uses SeeAllData=true in the test class, but in real implementations, you should create and manage your own test data to ensure proper isolation and reliability.

3.3 Apex Prehook in Action

The Apex Prehook updates the context by updating Adjustment Type column with a random discount percentage (between 5% and 15%) to each quote line. The pricing logic is then executed, using the updated context to calculate the Net Unit Price for every quote line accordingly