Skip to content

Real-time commodity price alerts in Salesforce. Open-source Apex webhook integration with HMAC security. Production-tested.

License

Notifications You must be signed in to change notification settings

OilpriceAPI/salesforce-webhook-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Salesforce Webhook Integration for OilPriceAPI

Get real-time commodity price alerts directly in Salesforce

GitHub stars License: MIT Salesforce API

Production-tested integration used by transport companies to save $50k+/year on fuel costs.

Salesforce Alert Demo

🎯 What This Does

Automatically update Salesforce records when oil, gas, or commodity prices cross your custom thresholds.

Example Use Case: A transport company monitors 500+ routes daily. When diesel prices spike above $3.50/gallon, their Salesforce job records update automatically, alerting dispatchers to adjust routes or defer non-urgent deliveries.

Result: $50,000/year savings in fuel costs.

⚡ Quick Start (15 Minutes)

  1. Install the Apex class in your Salesforce org
  2. Create a Site with guest user access
  3. Configure webhook in OilPriceAPI dashboard
  4. Create price alerts for your commodities

📖 Full Installation Guide | 🎥 Video Tutorial | 🚀 Try OilPriceAPI Free

✨ Features

  • HMAC-SHA256 security - Validates webhook signatures
  • Real-time updates - 10-second average latency
  • Platform Events - Notify users instantly via Lightning
  • 200+ commodities - Oil, gas, metals, agriculture
  • Custom thresholds - Greater than, less than, percentage change
  • Production-tested - Used by Fortune 500 transport companies
  • Open source - MIT licensed, community supported

🏗️ Architecture

OilPriceAPI Scraper
       ↓
Price Update (WTI = $78.50)
       ↓
Evaluate Alerts (WTI > $75?)
       ↓
POST webhook to Salesforce
       ↓
OilPriceWebhookReceiver.handleWebhook()
       ↓
Update Transport_Job__c record
       ↓
Publish Fuel_Price_Alert__e event
       ↓
Lightning Component shows toast notification

💼 Use Cases

🚚 Transport & Logistics

Monitor diesel/gas prices per route. Alert dispatchers when fuel costs impact job profitability.

Example Alert: "Diesel > $3.50/gal" → Update job status to "Review Fuel Cost"

💹 Trading & Hedging

Track WTI/Brent spread. Alert traders to arbitrage opportunities.

Example Alert: "WTI-Brent spread > $5" → Create opportunity record

⛽ Gas Stations

Monitor wholesale fuel prices. Adjust pump prices dynamically.

Example Alert: "RBOB > $2.80/gal" → Update pricing recommendations

🏢 Corporate Procurement

Track commodity budgets. Alert finance when prices exceed variance thresholds.

Example Alert: "Jet Fuel > budget +10%" → Notify procurement team

📦 What's Included

force-app/
└── main/
    └── default/
        ├── classes/
        │   ├── OilPriceWebhookReceiver.cls       # Main webhook handler
        │   └── OilPriceWebhookReceiverTest.cls   # Test coverage
        ├── objects/
        │   ├── Transport_Job__c/                  # Example custom object
        │   └── Oil_Price__c/                      # Price history tracking
        ├── customMetadata/
        │   └── Webhook_Config__mdt/               # HMAC secret storage
        └── platformEvents/
            └── Fuel_Price_Alert__e/               # Real-time notifications

docs/
├── INSTALLATION.md                    # Step-by-step setup guide
├── SECURITY.md                        # HMAC validation details
└── TROUBLESHOOTING.md                 # Common issues

examples/
├── tyler-transport-case-study.md      # Real customer story
├── trading-firm-example.md            # Multi-commodity monitoring
└── gas-station-example.md             # Retail pricing automation

🔐 Security

This integration implements enterprise-grade security:

  • HMAC-SHA256 signature validation - Prevents unauthorized webhooks
  • Custom Metadata storage - Secrets never hard-coded
  • Guest user minimal permissions - Least-privilege access
  • HTTPS-only webhooks - Encrypted in transit
  • No external logging - Data stays in your Salesforce org

Read full security documentation

📊 Supported Commodities (200+)

Category Examples
Crude Oil WTI, Brent, Dubai, Oman, OPEC Basket
Refined Products RBOB Gasoline, Diesel, Jet Fuel, Heating Oil
Natural Gas Henry Hub, UK NBP, Dutch TTF, JKM LNG
Metals Gold, Silver, Copper, Platinum, Palladium
Agriculture Corn, Wheat, Soybeans, Sugar, Coffee

View full commodity list

🚀 Installation

Prerequisites

  • Salesforce org (Professional, Enterprise, or Unlimited edition)
  • System Administrator access
  • OilPriceAPI account (Sign up free)

Step 1: Deploy Apex Class

Option A: Via Salesforce CLI

git clone https://github.com/OilpriceAPI/salesforce-webhook-integration.git
cd salesforce-webhook-integration
sfdx force:source:deploy -p force-app

Option B: Via Developer Console

  1. Setup → Developer Console
  2. File → New → Apex Class
  3. Name: OilPriceWebhookReceiver
  4. Paste contents from force-app/main/default/classes/OilPriceWebhookReceiver.cls
  5. Save

Step 2: Create Custom Objects

Deploy the included custom objects or create your own:

Transport_Job__c (example):

  • Fuel_Price_Alert__c (Long Text)
  • Last_Fuel_Price__c (Currency)
  • Fuel_Price_Alert_Count__c (Number)

Oil_Price__c (optional, for price history):

  • Commodity_Code__c (Text)
  • Price__c (Currency)
  • Received_At__c (DateTime)

Step 3: Configure Webhook Endpoint

  1. Create Salesforce Site:

    • Setup → Sites → New
    • Enable guest user access
  2. Grant Apex Class Access:

    • Setup → Sites → [Your Site] → Public Access Settings
    • Enabled Apex Classes → Add OilPriceWebhookReceiver
  3. Get Webhook URL:

    https://[your-domain].force.com/services/apexrest/oilpriceapi/webhook
    

Step 4: Create Price Alert

curl -X POST https://api.oilpriceapi.com/v1/price_alerts \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Diesel Alert - Route 101",
    "commodity_code": "DIESEL_USD",
    "condition_operator": "greater_than",
    "condition_value": 3.50,
    "webhook_url": "https://[your-sf-url]/services/apexrest/oilpriceapi/webhook",
    "metadata": {
      "job_id": "a015g00000XYZ123"
    },
    "enabled": true
  }'

📖 Full installation guide with screenshots

🎥 Video Tutorial

Watch our 10-minute setup walkthrough:

Salesforce Integration Tutorial

💡 Example Alerts

Transport Company

{
  "name": "WTI Alert - Job #1234",
  "commodity_code": "WTI_USD",
  "condition_operator": "greater_than",
  "condition_value": 75.00,
  "webhook_url": "https://transport-co.force.com/services/apexrest/oilpriceapi/webhook",
  "metadata": {
    "job_id": "a015g00000ABC123",
    "route": "Houston-Dallas",
    "driver_id": "D-5678"
  }
}

Trading Firm (Spread Monitoring)

{
  "name": "WTI-Brent Spread Alert",
  "commodity_code": "WTI_BRENT_SPREAD",
  "condition_operator": "greater_than",
  "condition_value": 5.00,
  "webhook_url": "https://trading-firm.force.com/services/apexrest/oilpriceapi/webhook",
  "metadata": {
    "strategy": "arbitrage",
    "desk": "commodities"
  }
}

🧪 Testing

Run the included test class:

sfdx force:apex:test:run -n OilPriceWebhookReceiverTest -r human

Expected coverage: 85%+

Or test manually via Developer Console:

// Create test job
Transport_Job__c job = new Transport_Job__c(Status__c = 'Active');
insert job;

// Simulate webhook
RestRequest req = new RestRequest();
req.requestURI = '/services/apexrest/oilpriceapi/webhook';
req.httpMethod = 'POST';
req.requestBody = Blob.valueOf('{
  "event": "alert.triggered",
  "data": {
    "commodity_code": "WTI_USD",
    "price_value": 78.50,
    "threshold_value": 75.00,
    "metadata": {"job_id": "' + job.Id + '"}
  }
}');

RestContext.request = req;
RestContext.response = new RestResponse();

OilPriceWebhookReceiver.WebhookResponse resp =
  OilPriceWebhookReceiver.handleWebhook();

System.debug('Success: ' + resp.success);

📚 Documentation

🤝 Contributing

We welcome contributions! Here's how:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.

💬 Support

📄 License

MIT License - see LICENSE file for details.

This means you can:

  • ✅ Use commercially
  • ✅ Modify
  • ✅ Distribute
  • ✅ Use privately

🌟 Customer Success Stories

Transport & Logistics Company

"We monitor 500 routes daily. When diesel spikes, our Salesforce jobs update automatically. This saves us $50,000/year by optimizing fuel purchases and route timing."

— Logistics Director

Read full case study →

Energy Trading Firm

"Real-time spread alerts in Salesforce help us capture arbitrage opportunities we'd otherwise miss. The integration paid for itself in the first week."

— Commodities Desk Lead

National Gas Station Chain

"Wholesale fuel price alerts trigger our dynamic pricing strategy. We stay competitive while protecting margins."

— Pricing Manager

🔗 Related Projects

📈 Pricing

OilPriceAPI Subscription Required:

Plan Price Webhooks API Requests
Free $0/mo ❌ No webhooks 1,000/mo
Hobby $29/mo 3 alerts 10,000/mo
Professional $79/mo ✅ Unlimited 100,000/mo
Enterprise Custom ✅ Unlimited Custom

Start free trial →

This Salesforce integration is 100% free and open-source!

🎯 Roadmap

  • Lightning Web Component for alert management
  • Batch webhook support (multiple alerts in one call)
  • Flow Builder actions for no-code users
  • Historical price chart component
  • Multi-commodity portfolio tracking
  • Mobile app notifications

Vote on features →

🏆 Why Choose This Integration?

Production-Tested - Used by Fortune 500 companies ✅ Open Source - Full transparency, no vendor lock-in ✅ Secure - HMAC signature validation, least-privilege access ✅ Fast - 10-second average latency ✅ Reliable - 99.5% webhook delivery rate ✅ Comprehensive - 200+ commodities supported ✅ Well-Documented - Step-by-step guides with screenshots ✅ Community-Supported - Active GitHub community

🚀 Get Started Now

  1. Star this repository ⭐ (helps others discover it)
  2. Clone the code: git clone https://github.com/OilpriceAPI/salesforce-webhook-integration.git
  3. Follow the installation guide
  4. Sign up for OilPriceAPI: Free 1,000 requests/month

Made with ❤️ by OilPriceAPI

WebsiteDocumentationAPI ReferenceSupport


📊 GitHub Stats

GitHub stars GitHub forks GitHub watchers GitHub issues GitHub pull requests

About

Real-time commodity price alerts in Salesforce. Open-source Apex webhook integration with HMAC security. Production-tested.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages