Environments

Environments are the central concept in a Flxbl project. An environment links a repository branch to a registered Salesforce org, providing controlled access to credentials for team members and CI/CD pipelines.

Orgs vs Environments

Understanding the distinction between Orgs and Environments is essential:

ConceptDescriptionScope
OrgA registered Salesforce org (production, sandbox, scratch org) with stored credentialsGlobal - shared across all repositories
EnvironmentA deployment target that links a repository + branch to a registered orgRepository-specific
┌─────────────────────────────────────────────────────────────────────────────┐
│                         Orgs vs Environments                                 │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   REGISTERED ORGS (Global)           ENVIRONMENTS (Per Repository)          │
│   ────────────────────────           ─────────────────────────────          │
│                                                                              │
│   admin@production.com    ─────────► Production (myorg/app-1, main)         │
│                           └────────► Production (myorg/app-2, main)         │
│                                                                              │
│   admin@prod--uat.sandbox ─────────► UAT (myorg/app-1, release/*)           │
│                           └────────► QA (myorg/app-2, develop)              │
│                                                                              │
│   admin@devhub.com        ─────────► (DevHub for scratch org pools)         │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

Key differences:

Org Commands (sfp server org)Environment Commands (sfp server environment)
Register Salesforce credentialsLink orgs to repository branches
Store/update auth detailsControl access via locking
JIT sandbox registrationProvide deployment targets
Direct org access via org loginCredential access requires lock or --auth-type

What is an Environment?

An environment represents a deployment target - the combination of:

  • Repository: Which codebase (e.g., myorg/salesforce-app)
  • Branch: Which code branch (e.g., main, develop)
  • Salesforce Org: Which org to install artifacts
  • Category: The environment type (dev, test, release)
Environment: "UAT"
├── Repository: myorg/salesforce-app
├── Branch: release/v2.0
├── Salesforce Org: admin@uat.sandbox.com  (must be registered first)
├── Category: test
└── Metadata: { "region": "US", "owner": "qa-team" }

Environment Categories

CategoryPurposeTypical Use
devDevelopmentFeature development, local testing
testTestingUAT, SIT, QA environments
snapshotSnapshotsPoint-in-time environment copies
releaseProductionProduction and staging releases

Complete Setup: From Org to Environment

Before creating environments, you need to register your Salesforce orgs with sfp-server. Here's the complete flow:

┌─────────────────────────────────────────────────────────────────────────────┐
│                    Environment Setup Flow                                    │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   STEP 1: Register Salesforce Orgs                                           │
│   ────────────────────────────────                                           │
│                                                                              │
│   # Production org (requires local auth first)                               │
│   $ sf org login web --alias production                                      │
│   $ sfp server org register --targetusername production                      │
│                                                                              │
│   # DevHub (if using scratch orgs)                                           │
│   $ sf org login web --alias devhub                                          │
│   $ sfp server org register --targetusername devhub --devhub --default       │
│                                                                              │
│   # Sandboxes (option A: JIT - recommended)                                  │
│   $ sfp server org register-sandbox \                                        │
│       --sandboxname uat \                                                    │
│       --productionusername admin@production.com                              │
│                                                                              │
│   # Sandboxes (option B: direct registration)                                │
│   $ sf org login web --alias uat --instance-url https://test.salesforce.com  │
│   $ sfp server org register --targetusername uat                             │
│                                                                              │
│   STEP 2: Create Environments                                                │
│   ───────────────────────────                                                │
│                                                                              │
│   $ sfp server environment create \                                          │
│       --repository myorg/salesforce-app \                                    │
│       --name UAT \                                                           │
│       --category test \                                                      │
│       --branch release/* \                                                   │
│       --targetusername admin@production--uat.sandbox.com                     │
│                                                                              │
│   STEP 3: Access Environments                                                │
│   ───────────────────────────                                                │
│                                                                              │
│   $ sfp server environment get \                                             │
│       --name UAT \                                                           │
│       --repository myorg/salesforce-app \                                    │
│       --auth-type accessToken \                                              │
│       --authenticate                                                         │
│                                                                              │
│   ✅ Ready to use: sfp install --targetorg UAT --artifactdir ./artifacts     │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

Step 1: Register Orgs

First, register your Salesforce orgs with sfp-server. See Org Registration for complete details.

Step 2: Create Environments

Link registered orgs to repository branches.

Creating Environments

Basic Creation

sfp server environment create \
  --repository myorg/salesforce-app \
  --name UAT \
  --category test \
  --branch release/v2.0 \
  --description "User Acceptance Testing environment" \
  --targetusername admin@uat.sandbox.com

With Metadata and Tags

sfp server environment create \
  --repository myorg/salesforce-app \
  --name Production \
  --category release \
  --branch main \
  --description "Production environment" \
  --targetusername admin@production.com \
  --tags "critical,monitored" \
  --metadata '{"region": "US-WEST", "sla": "99.9%"}'

Listing Environments

List All

sfp server environment list --repository myorg/salesforce-app

Output:

┌─────────────┬──────────┬─────────────────┬────────────────────────────┬────────┐
│ Name        │ Category │ Branch          │ Salesforce Org             │ Active │
├─────────────┼──────────┼─────────────────┼────────────────────────────┼────────┤
│ Production  │ release  │ main            │ admin@production.com       │ Yes    │
│ Staging     │ release  │ release/*       │ admin@staging.sandbox.com  │ Yes    │
│ UAT         │ test     │ release/v2.0    │ admin@uat.sandbox.com      │ Yes    │
│ SIT         │ test     │ develop         │ admin@sit.sandbox.com      │ Yes    │
│ Dev         │ dev      │ feature/*       │ admin@dev.sandbox.com      │ Yes    │
└─────────────┴──────────┴─────────────────┴────────────────────────────┴────────┘

Filter by Category

sfp server environment list --repository myorg/salesforce-app --category test

Retrieving Environments

Basic Retrieval (No Credentials)

Get environment information without credentials:

sfp server environment get --name UAT --repository myorg/salesforce-app

Credential Access Methods

There are two ways to get credentials for an environment:

Method 1: Lock-Based Access (For Deployments)

Recommended for CI/CD and deployments. Locking prevents concurrent deployments from conflicting with each other.

# Step 1: Request a lock
sfp server environment lock \
  --name UAT \
  --repository myorg/salesforce-app \
  --duration 30 \
  --reason "Deploying release v2.0"

# Output: Ticket ID: lock-abc123

# Step 2: Use the ticket to get credentials and authenticate
sfp server environment get \
  --name UAT \
  --repository myorg/salesforce-app \
  --lock-ticket-id lock-abc123 \
  --authenticate

# Step 3: After deployment, release the lock
sfp server environment unlock \
  --name UAT \
  --repository myorg/salesforce-app \
  --ticket-id lock-abc123

Method 2: Direct Access with --auth-type (No Locking)

For testing and read-only operations only. Do not use for deployments - without locking, concurrent operations may conflict.

sfp server environment get \
  --name UAT \
  --repository myorg/salesforce-app \
  --auth-type accessToken \
  --authenticate

This retrieves a short-lived access token (~2 hours) and authenticates locally.

When to Use Which Method

ScenarioMethodWhy
CI/CD deploymentsLock-basedPrevents concurrent deployments
Running tests--auth-typeNo locking overhead needed
Quick data queries--auth-typeRead-only, no conflict risk
Long-running operationsLock with --waitEnsures exclusive access
Parallel pipeline jobsLock-basedQueue management

Auth Type Selection

Auth TypeLifetimeUse Case
accessToken~2 hoursShort operations, better security
sfdxAuthUrlUntil revokedScratch org pools, extended sessions

Environment Properties

Core Properties

PropertyDescription
nameUnique name within repository
categorydev, test, snapshot, release
branchGit branch pattern
descriptionHuman-readable description
salesforceUsernameLinked Salesforce org
isActiveWhether environment is active
isDefaultDefault for its category

Extended Properties

PropertyDescription
tagsSearchable tags
metadataCustom JSON metadata
orchestrationOrderDeployment sequence
devHubUsernameParent org (for sandboxes)

Lock Status

When an environment is locked:

{
  "name": "UAT",
  "isLocked": true,
  "lockStatus": {
    "isLocked": true,
    "currentLock": {
      "lockedBy": "ci-pipeline",
      "lockReason": "Deployment in progress",
      "expiresAt": "2024-01-15T14:30:00Z",
      "expiresInSeconds": 1800
    },
    "queuedLocks": [
      {
        "position": 1,
        "requestedBy": "developer@company.com",
        "ticketId": "lock-abc123"
      }
    ]
  }
}

Updating Environments

sfp server environment update \
  --name UAT \
  --repository myorg/salesforce-app \
  --description "Updated UAT for Q2 release" \
  --tags "critical,q2-release"

Deleting Environments

sfp server environment delete \
  --name old-dev \
  --repository myorg/salesforce-app

Credential Access Control

Role-Based Access

RoleCan ViewCan Get CredentialsCan Modify
MemberYesNoNo
OwnerYesYesYes
ApplicationYesYesLimited

Audit Trail

All credential access is logged:

# View access audit (owners only)
sfp server environment audit --name UAT --repository myorg/salesforce-app

CI/CD Integration

GitHub Actions

jobs:
  deploy-to-uat:
    runs-on: ubuntu-latest
    env:
      SFP_SERVER_URL: ${{ secrets.SFP_SERVER_URL }}
      SFP_SERVER_TOKEN: ${{ secrets.SFP_SERVER_TOKEN }}
    steps:
      - uses: actions/checkout@v4

      - name: Authenticate to UAT
        run: |
          sfp server environment get \
            --name UAT \
            --repository ${{ github.repository }} \
            --auth-type accessToken \
            --authenticate

      - name: Deploy
        run: |
          sfp install --targetorg UAT --artifactdir ./artifacts

Matrix Deployment

jobs:
  deploy:
    strategy:
      matrix:
        environment: [SIT, UAT, Staging]
    runs-on: ubuntu-latest
    steps:
      - name: Authenticate
        run: |
          sfp server environment get \
            --name ${{ matrix.environment }} \
            --repository ${{ github.repository }} \
            --auth-type accessToken \
            --authenticate

      - name: Deploy to ${{ matrix.environment }}
        run: |
          sfp install --targetorg ${{ matrix.environment }} --artifactdir ./artifacts

Environment Patterns

Standard Pipeline

Repository: myorg/salesforce-app

Environments:
├── Dev (dev) ────────> feature branches

├── SIT (test) ────────> main

├── UAT (test) ────────> main

├── Staging (release) ─> main 

└── Production (release) ─> main branch

Multi-Region

Environments:
├── Production-US (release, tags: ["us", "primary"])
├── Production-EU (release, tags: ["eu", "gdpr"])
└── Production-APAC (release, tags: ["apac"])

Feature Environments

Environments:
├── Feature-Auth (dev, branch: feature/auth-*)
├── Feature-Payments (dev, branch: feature/payments-*)
└── Feature-Reports (dev, branch: feature/reports-*)

On this page