Salesforce

Salesforce Discount Approval with Corules Policy Enforcement

Enforce discount limits inside Salesforce Flow before Opportunity records are updated. Gate 1 returns allowed discount bounds per customer tier. Gate 2 validates the rep's proposed discount before saving.

Overview

This integration connects Salesforce with Corules's policy enforcement runtime. Your existing Salesforce workflows call Corules's REST API (or MCP server) to enforce policy constraints before any business action completes.

All policy logic stays in Corules — your Salesforce configuration only needs to call the endpoint and route based on the ALLOW / BLOCK / ESCALATE response.

Setup steps

  1. 1

    Add a Named Credential in Salesforce Setup for the Corules API endpoint

  2. 2

    Create a Screen Flow on Opportunity triggered when Discount_Percent__c changes

  3. 3

    Add an HTTP Callout action to POST /v1/validate with the opportunity context and proposed discount

  4. 4

    Branch on outcome: ALLOW → save record, ESCALATE → route to manager approval, BLOCK → show error with allowed range

  5. 5

    Store the returned audit_id on the Opportunity record for traceability

Code example

The following snippet shows how to call Corules from Salesforce. Replace YOUR_USE_CASE_ID and YOUR_API_KEY with your tenant credentials.

// Salesforce Apex callout to Corules Gate 2
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Corules/v1/validate');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setHeader('X-Correlation-Id', correlationId);
req.setHeader('X-Idempotency-Key', idempotencyKey);

req.setBody(JSON.serialize(new Map<String, Object>{
  'use_case' => 'discount_approval',
  'actor'    => UserInfo.getUserId(),
  'context'  => new Map<String, Object>{
    'deal_value'      => opp.Amount,
    'discount_pct'    => opp.Discount_Percent__c / 100,
    'customer_tier'   => opp.Account.Tier__c,
    'product_category'=> opp.Product_Category__c
  },
  'decision' => new Map<String, Object>{
    'discount_pct' => opp.Discount_Percent__c / 100
  }
}));

Http http = new Http();
HttpResponse res = http.send(req);
Map<String, Object> body = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
String outcome = (String) body.get('outcome');

Language: apex

Frequently Asked Questions

Does this require changes to existing Salesforce data models?

No structural changes required. Add one custom field (Corules_Audit_Id__c) on Opportunity to store the audit reference. Everything else runs through the Flow.

Can this work inside Salesforce Flow Builder without Apex?

Yes. Use Flow's HTTP Callout action (GA in Summer '24) for a no-code integration. Apex is only needed for complex conditional logic or bulk processing.

How does the actor identity work for Salesforce users?

The actor field carries UserInfo.getUserId() from Salesforce. Corules resolves this to a policy actor with the appropriate role and permissions configured in tenant settings.

Connect Salesforce to Corules

Start free — integration templates are available on every plan.

Get started free