# Usual Command Flows - Sprint Release and Change Flow

This flow describes the process when code is promoted through environments during sprint releases.

### 1. Pre-Release - Complete Feature Work

<div class="codehilite" id="bkmrk-"><div class="code-buttons" data-partial-update-ignore="true">  
</div></div><div class="codehilite" id="bkmrk-bash"><span class="filename">Bash</span></div>```
# Ensure all changes are committed
git status
sf project retrieve start --target-org my-scratch-org
git add .
git commit -m "TICKET-123: Final implementation"
git push origin feature/my-ticket-branch
```

### 2. Create Pull Request

**Via BitBucket UI:**

- Navigate to your repository in BitBucket
- Click "Create Pull Request"
- Source: `feature/my-ticket-branch`
- Destination: `main` (or current sprint branch)
- Add description and link to ticket

### 3. Pipeline Validation (Automated)

BitBucket automatically triggers:

<div class="codehilite" id="bkmrk-yaml"><span class="filename">Yaml</span></div>```
# This happens automatically in the pipeline
# Code Analyzer steps
pmd-analyzer: Check Apex code quality
eslint: Check JavaScript/LWC quality
sf scanner run: Security and quality scans

# Validation deployment
sf project deploy validate --target-org target-sandbox --test-level RunLocalTests

```

**If validation fails**: Technical Architect reviews and adds fixes to PR branch.

### 4. Pull Request Merge

Once validation passes and PR is approved:<span class="filename">Bash</span>

```
# Via BitBucket UI - Click "Merge" button
```

### 5. Post-Merge Deployment (Automated)

#### Option A: Simple Deployment (No Destructive Changes)

<div class="codehilite" id="bkmrk--1"><div class="code-buttons" data-partial-update-ignore="true">  
</div></div><div class="codehilite" id="bkmrk-bash-1"><span class="filename">Bash</span></div>```
# Automated pipeline command
sf project deploy start --target-org target-sandbox --test-level RunLocalTests --wait 30
```

#### Option B: SGD - Salesforce Git Delta Deploy (With Destructive Changes)

<div class="codehilite" id="bkmrk--2"><div class="code-buttons" data-partial-update-ignore="true">  
</div></div><div class="codehilite" id="bkmrk-bash-2"><span class="filename">Bash</span></div>```
# Automated pipeline using SGD tool
# Generates delta packages between commits

# Install SGD (if not already in pipeline)
sf plugins install sfdx-git-delta

# Generate delta package
sf sgd source delta --to "HEAD" --from "HEAD~1" --output-dir "sgd"

# Deploy with destructive changes
sf project deploy start -x sdg/package/package.xml --post-destructive-changes sdg/destructiveChanges/destructiveChanges.xml

```

### 9. Rollback (If Needed)

<div class="codehilite" id="bkmrk--3"><div class="code-buttons" data-partial-update-ignore="true">  
</div></div><div class="codehilite" id="bkmrk-bash-3"><span class="filename">Bash</span></div>```
# Quick rollback using git
git revert <commit-hash>
git push origin main

# Or restore from previous deployment
sf project deploy start --manifest path/to/previous-package.xml --target-org target-sandbox

```

---