Skip to content

salesforce-misc/NZC-Water-Footprint-Automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ’§ Water Footprint Automation

A Salesforce Net Zero Cloud accelerator for automatic water footprint linking, built with Apex Enterprise Patterns (fflib)

Salesforce Net Zero Cloud Apex

πŸš€ Quick Deploy

Deploy to Salesforce

One-click deployment to your Salesforce org

Note: Replace YOUR_GITHUB_ORG with your GitHub username or organization. Alternatively, use the Salesforce CLI deployment method below.


✨ Features

πŸ’§ Water Footprint Automation

  • Automatic Footprint Linking: On insert of StnryAssetWaterActvty records, finds or creates matching StnryAssetWaterFtprnt records
  • Schema-Aware: Handles StartDate/StrtDt field variations across Net Zero Cloud orgs
  • Unit of Work: All DML via fflib_SObjectUnitOfWork for bulkified, transactional operations

πŸ—οΈ Enterprise Patterns

  • Selector/Service Layering: Encapsulated SOQL in Selectors, business logic in Services
  • fflib Integration: Trimmed fflib subset (UnitOfWork, Selector, Application) β€” no mocks
  • Dependency Injection: Application.cls factory for UnitOfWork and Selector resolution

πŸš€ Getting Started

πŸ“‹ Prerequisites

Before you begin, ensure you have the following:

  • βœ… Salesforce Net Zero Cloud licensed and configured
  • βœ… Git installed on your local machine
  • βœ… Salesforce CLI (latest version recommended)
  • βœ… Salesforce user with deployment permissions
  • βœ… Active Salesforce org (Sandbox or Developer Edition)

πŸ”§ Installation

Choose your preferred deployment method:

🎯 Option 1: One-Click GitHub Deploy (Recommended)

Click the "Deploy to Salesforce" button above for instant deployment to your org. Ensure you replace YOUR_GITHUB_ORG in the deploy URL with your GitHub username or organization.

πŸ“¦ Option 2: Workbench Deployment

For environments where GitHub access is restricted:

  1. Download the pre-built deployment package:
  2. Navigate to Salesforce Workbench
  3. Login to your target org
  4. Go to Migration β†’ Deploy
  5. Upload the zip file and deploy

Alternative Tools: You can also deploy using Salesforce Inspector or the Ant Migration Tool.

πŸ› οΈ Option 3: Salesforce CLI Deployment

For developers who prefer command-line tools:

3.1 Clone the Repository
git clone https://github.com/YOUR_GITHUB_ORG/water-footprint-automation.git
cd water-footprint-automation
3.2 Authorize Your Org
# For sandbox/production orgs
sf org login web --alias MyOrg --instance-url https://test.salesforce.com

# For developer orgs
sf org login web --alias MyOrg
3.3 Deploy the Metadata
# Deploy all components (Salesforce CLI v2)
sf project deploy start --source-dir force-app --target-org MyOrg

# Or using legacy sfdx command
sfdx project deploy start --source-dir force-app --target-org MyOrg

Note: This accelerator is compatible with CI/CD tools like Gearset, Copado, and Flosum.


⚑ Post-Deployment Configuration

After deploying with any method above, complete these manual steps:

  1. Verify Net Zero Cloud Objects

    • Ensure StnryAssetWaterActvty, StnryAssetWaterFtprnt, and StnryAssetEnvrSrc exist in your org
    • The trigger and service expect standard Net Zero Cloud schema
  2. Assign Permissions

    • Grant users access to the custom classes and trigger as needed
    • Ensure profiles/permission sets include access to StnryAssetWaterActvty and StnryAssetWaterFtprnt

🎯 Usage

πŸ’§ Water Footprint Flow (Automatic)

The StnryAssetWaterActvty trigger runs automatically on insert:

  1. Create StnryAssetWaterActvty records (via UI, API, or Data Loader)
  2. Trigger fires after insert and delegates to StnryAssetWaterActvtyService.linkOrCreateFootprints()
  3. Service finds or creates matching StnryAssetWaterFtprnt records and populates StnryAssetWaterFtprntId on activities
  4. No manual steps required β€” footprint linking is fully automated

πŸ—οΈ Technical Architecture

This accelerator contains the following metadata:

  • 1 Trigger (StnryAssetWaterActvtyTrigger)
  • 4 Custom Apex Classes (StnryAssetWaterActvtyService, StnryAssetWaterFtprntSelector, StnryAssetWaterSchema, Application)
  • 4 Test Classes (StnryAssetWaterActvtyServiceTest, StnryAssetWaterActvtyTriggerTest, StnryAssetWaterFtprntSelectorTest, StnryAssetWaterSchemaTest)
  • fflib Framework (trimmed subset: UnitOfWork, Selector, Application, QueryFactory, SObjects, etc.)

Architecture Diagram

graph TB
    A[StnryAssetWaterActvtyTrigger] --> B[StnryAssetWaterActvtyService]
    B --> C[StnryAssetWaterFtprntSelector]
    B --> D[fflib_SObjectUnitOfWork]
    C --> E[StnryAssetWaterFtprnt]
    B --> F[StnryAssetWaterSchema]
    D --> G[StnryAssetWaterActvty]
    D --> E
Loading

🧩 Key Components

Component Description
StnryAssetWaterActvtyTrigger After-insert trigger; delegates to Service for footprint linking
StnryAssetWaterActvtyService Orchestrates find-or-create footprint logic; uses Selector and UnitOfWork
StnryAssetWaterFtprntSelector Encapsulates SOQL for StnryAssetWaterFtprnt; selectByEnvrSrcIdsAndDateRange()
StnryAssetWaterSchema Discovers date field API names (handles org schema variations)
Application DI factory for UnitOfWork and Selector resolution

🀝 Contributing

We welcome contributions to improve Water Footprint Automation! See CONTRIBUTING.md for detailed guidelines. In short:

  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

πŸ“ Development Guidelines

  • Follow Salesforce coding standards
  • Adhere to Apex Enterprise Patterns in .cursor/rules/Apex Rules.mdc (Selector/Service layering, UnitOfWork)
  • Include comprehensive test coverage (>75%)
  • Update documentation for new features
  • Test thoroughly in multiple org types

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


πŸ› How to Report Bugs

Found a bug or have a feature request? Please report it via GitHub Issues.

When reporting bugs, please include:

  • Steps to reproduce the issue
  • Expected vs. actual behavior
  • Salesforce org version and edition
  • Screenshots or error messages (if applicable)

πŸ†˜ Support


⚠️ Disclaimer

This accelerator is open-source, not an official Salesforce product, and is community-supported. Salesforce does not provide official support for this accelerator. Use at your own risk and test thoroughly in a sandbox environment before deploying to production.


Made with ❀️ for the Salesforce Community

⭐ Star this repo if you find it helpful!

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Generated from salesforce/oss-template