# Test Case: Lead Object — Setup Configuration & Behavior Validation

> **Test ID**: LEAD-SETUP-001
> **Priority**: P1
> **Test Environment**: NexusCRM (https://nexuscrm.pingcap.com)
> **Last Updated**: 2026-03-30
> **Test Agent**: dev-browser (manual exploration by Claude)

## 1. Test Overview

This test validates that Salesforce Setup configurations for the Lead object are correctly reflected in NexusCRM runtime behavior. It covers 5 configuration groups:

1. **Page Layouts** — Layout config vs Detail/Edit/List View rendering
2. **Validation Rules** — Rule config vs save-time enforcement
3. **Flows** — Lead-related automation flows
4. **Approval Processes** — Lead approval workflow configuration
5. **Email Templates** — Lead-related templates

**Key Finding**: Page Layouts and Validation Rules both fail to load in Setup (null pointer errors), which explains multiple runtime issues observed in the core Lead tests (PR #509).

---

## 2. Prerequisites

- **Environment**: NexusCRM (Salesforce-direct mode via OAuth to `pingcap--partialcop.sandbox.my.salesforce.com`)
- **Authentication**: Salesforce OAuth (logged in manually)
- **Browser Tool**: dev-browser CLI
- **Prior Test**: Core Lead paths from PR #509 completed

---

## 3. Test Steps

### Group 1: Page Layouts

#### TC-LEAD-PL01: Read Page Layout Configuration

**Objective**: Check what page layouts are configured for Lead in Setup > Object Manager

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Navigate to `/setup/objects/Lead` | Lead object setup page loads | Page loaded. Heading "Lead". Tabs: Fields & Relationships, Page Layouts, Validation Rules, Details | Pass |
| 2 | Click "Page Layouts" tab | List of configured page layouts | **Error**: "Failed to load layouts: Cannot read properties of null (reading 'layouts')" — empty list, no layouts shown | Fail |
| 3 | Check for "New Layout" button | Button should be available | "New Layout" button exists | Pass |

⚠️ **Known Issue**: Page Layouts API returns null, causing a JavaScript null pointer error. No layouts can be viewed or managed.

**Reference Screenshot**: `screenshots/lead-setup/page_layouts_list.png`

---

#### TC-LEAD-PL02: Compare Layout Config vs Detail View

**Objective**: Determine if the Detail View renders fields from a layout or falls back to showing all fields

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Navigate to Lead detail (`/object/Lead/00QRC00000beDkd2AE`) | Detail page loads | Page loaded for "Rima M." | Pass |
| 2 | Check for "No page layout assigned" message | Should not appear if layout is configured | Message NOT present (may have been fixed since PR #509) | Pass |
| 3 | Record all field sections | Sections should match layout config | 10 sections found: LEAD, IQM QUALITY SCORING, ACCOUNT, TIDB CLOUD, ADDRESS, DESCRIPTION, AWS INFORMATION, HUBSPOT INFORMATION, HUBSPOT INTELLIGENCE, SYSTEM INFORMATION | N/A |
| 4 | Check Related List Quick Links | Should match layout-configured related lists | 5 quick links: Cloud User Request (0), Notes (0), Files (0), Lead History (0), Campaign History (0) | N/A |
| 5 | Check for Details / Related tabs | Tabs present | Both tabs visible | Pass |

**Note**: Cannot compare with layout config since PL01 failed to load layouts. The detail page renders 10 sections and 5 related list quick links — this appears to be a reasonable layout, but whether it matches the Salesforce-configured layout cannot be verified.

**Observed Detail Page Structure**:

| Section | Fields (sample) |
|---------|----------------|
| LEAD | Name, Title, Job Function, Lead Owner, Email, Status, Lifecycle Stage, etc. |
| IQM QUALITY SCORING | Job Role, Primary Need/Pain, Budget, Authority, Team, Next Steps, Timing |
| ACCOUNT | Account (Dell), Region (NA), Company, HQ Country, Employee Number, Annual Revenue, Industry, Vertical |
| TIDB CLOUD | TiDB Cloud User, Connection Type, Tenant Status, Registration Status |
| ADDRESS | Address, Time Zone, IP Country, IP City |
| DESCRIPTION | Key Messages, Comments |
| AWS INFORMATION | AWS Status, AWS Lead Stage, AWS Campaign Name |
| HUBSPOT INFORMATION | Hubspot Original Source, HubSpot Source Drill-Down |
| HUBSPOT INTELLIGENCE | UTM parameters (medium, campaign, source, term, content) |
| SYSTEM INFORMATION | Approval Chain |

**Related List Quick Links**: Cloud User Request (0), Notes (0), Files (0), Lead History (0), Campaign History (0)

**Reference Screenshot**: `screenshots/lead-setup/detail_no_layout.png`

---

#### TC-LEAD-PL03: Compare Layout Config vs Edit Form

**Objective**: Check if the Edit form renders layout-defined fields or all 292/348 fields

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Open Lead edit form | Edit form loads | 292 input fields rendered (from E01 test) | N/A |
| 2 | Compare field count: Layout config vs Edit form | Edit form should show layout-configured fields only | Layout config unavailable (PL01 error). Object has 348 fields total, edit form shows 292. | N/A |
| 3 | Check if edit form has sections | Should match layout sections | Edit form renders sections matching detail view (Lead, IQM Quality Scoring, Account, etc.) | Pass |

**Hypothesis**: The edit form shows 292 of 348 fields (likely excluding read-only/formula/system fields). Whether this matches the layout or is a fallback to "all editable fields" cannot be determined until PL01 is fixed.

---

#### TC-LEAD-PL04: List View Configuration

**Objective**: Check if list view columns match any saved configuration

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Observe Lead list columns | Columns should match list view config | Columns: Full Name, Status, Last Name, Company, Email Opt Out, Converted | N/A |
| 2 | Open Column Picker | SELECTED count should match visible columns | SELECTED (0) but 6 columns visible — mismatch (confirmed in L03) | Fail |

**Note**: The column picker shows "Selected (0)" despite 6 visible columns. This suggests the list view is using default columns not saved to any configuration, or the column persistence mechanism is broken.

---

### Group 2: Validation Rules

#### TC-LEAD-VR01: Read Validation Rules Configuration

**Objective**: Check what validation rules are configured for Lead

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Navigate to `/setup/objects/Lead` | Lead object page loads | Page loaded | Pass |
| 2 | Click "Validation Rules" tab | List of validation rules | **Error**: "Cannot read properties of null (reading 'rules')" — no rules shown | Fail |

⚠️ **Known Issue**: Validation Rules API returns null, same pattern as Page Layouts. No rules can be viewed or managed.

**Reference Screenshot**: `screenshots/lead-setup/validation_rules_list.png`

---

#### TC-LEAD-VR02: Verify Validation Behavior on Edit

**Objective**: Even though VR01 config failed to load, check if validation actually fires at runtime

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Open Lead edit form, clear Last Name, click Save | Validation error should fire | "Please correct the errors below" + "This field is required" (confirmed in E03) | Pass |
| 2 | Check error message format | Should be user-friendly | User-friendly: "This field is required" | Pass |

**Note**: Required field validation works at runtime even though the Validation Rules setup page fails to load. This suggests required-field validation is handled by the form component (client-side), not by Salesforce-style server-side validation rules.

---

#### TC-LEAD-VR03: Verify Validation Behavior on Create

**Objective**: Check if validation fires during Lead creation

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Open New Lead form, fill Company + Status, click Save | Validation error for missing required fields | "Please correct the errors below — 1 field requires attention." Error on Lead Owner field: "This field is required" | Pass |
| 2 | Check which fields are validated | Required fields should be enforced | Lead Owner* is enforced. Note: LastName is NOT enforced because the Name compound field doesn't render LastName input (see Issue #517) | Partial |

**Key Observation**:
- Lead Owner validation fires correctly
- LastName validation cannot fire because the input doesn't exist (compound Name field bug)
- No Salesforce-style custom validation rules observed (formula-based rules) — may not be implemented

---

### Group 3: Flows

#### TC-LEAD-FL01: Identify Lead-Related Flows

**Objective**: Find all flows that involve the Lead object

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Navigate to `/setup/flows` | Flows list loads | 20 flows displayed (paginated, may be more) | Pass |
| 2 | Search for Lead-related flows | Flows with Lead in name or trigger | 4 Lead-related flows found | Pass |

**Lead-Related Flows Found**:

| Flow Name | API Name | Type | Status | Last Modified |
|-----------|----------|------|--------|---------------|
| Account_And_Lead_Sum_Approval_Poc | Account_And_Lead_Sum_Approval_Poc | AutoLaunchedFlow | Active | 5/18/2022 |
| Account_Related_Leads_Based_on_Website_Domain_Create | Account_Related_Leads_Based_on_Website_Domain_Create | AutoLaunchedFlow | Active | 6/20/2024 |
| Account_Related_Leads_Based_on_Website_Domain_Update | Account_Related_Leads_Based_on_Website_Domain_Update | AutoLaunchedFlow | Active | 6/20/2024 |
| APAC_Lead_Priority | APAC_Lead_Priority | Workflow | Inactive | 5/10/2023 |

**Note**: All active Lead flows are AutoLaunchedFlows related to Account-Lead relationships, not direct Lead CRUD triggers. APAC_Lead_Priority is inactive. Flow behavior cannot be verified without creating/updating Lead records (blocked by Issues #516, #517, #518).

**Reference Screenshot**: `screenshots/lead-setup/flows_page.png`

---

#### TC-LEAD-FL02: Verify Flow Behavior

**Objective**: Check if Lead flows fire on record changes

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Check if any flow fires on Lead edit | Observable side effects | Cannot verify — Lead edit save is blocked by Vertical picklist encoding bug (Issue #516) | Blocked |
| 2 | Check if any flow fires on Lead create | Observable side effects | Cannot verify — Lead creation is blocked (Issues #517, #518) | Blocked |

**Note**: Flow behavior verification is entirely blocked by the edit/create bugs. This should be retested once Issues #516, #517, #518 are resolved.

---

### Group 4: Approval Processes

#### TC-LEAD-AP01: Identify Lead Approval Processes

**Objective**: Check if Lead has any configured approval processes

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Navigate to `/setup/approval-processes` | Approval processes list loads | 20 processes displayed | Pass |
| 2 | Filter by Object = "Lead" | Lead approval processes shown | No "Lead" option in the Object filter dropdown | N/A |
| 3 | Search in full list for Lead-related processes | Any Lead processes found | No processes with "Lead" in name | N/A |

**Conclusion**: Lead has no configured approval processes. The "Submit for Approval" button on the Lead detail page exists as a generic action but there is no Lead-specific approval process to route to.

**Reference Screenshot**: `screenshots/lead-setup/approval_processes_page.png`

---

#### TC-LEAD-AP02: Verify Submit for Approval Behavior

**Objective**: Check what happens when "Submit for Approval" is clicked without a configured process

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Confirm "Submit for Approval" button exists on Lead detail | Button present | Button confirmed present (from D01) | Pass |
| 2 | Expected behavior with no approval process | Should show error "No applicable approval process" or similar | Not tested — would need to click the button to verify | Pending |

**Note**: Clicking "Submit for Approval" without a configured process should show an error. This is a low-risk test that can be executed in a follow-up.

---

### Group 5: Email Templates

#### TC-LEAD-ET01: Identify Lead-Related Email Templates

**Objective**: Check for email templates that reference Lead

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Navigate to `/setup/email-templates` | Email templates page loads | Page loaded with heading "Email-templates" | Pass |
| 2 | Check for any templates | Templates listed | **0 templates** — page is completely empty | N/A |

**Conclusion**: No email templates exist in this environment. This may be an unfinished feature or the templates were not migrated from Salesforce.

**Reference Screenshot**: `screenshots/lead-setup/email_templates_page.png`

---

### Group 6: Supplementary Paths (Compact Layout, Related Lists, Submit for Approval)

#### TC-LEAD-CL01: Compact Layout Configuration

**Objective**: Check if Compact Layout is configurable for Lead in Object Manager

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Navigate to `/setup/objects/Lead` | Lead object setup page loads | Page loaded with 4 tabs: Fields & Relationships, Page Layouts, Validation Rules, Details | Pass |
| 2 | Look for "Compact Layouts" tab | Tab should exist (Salesforce has it) | **Not present** — only 4 tabs available, no Compact Layouts | Fail |

**Conclusion**: Compact Layout management is not implemented in NexusCRM Object Manager. In Salesforce, Compact Layouts control which fields appear in record highlights (top of detail page), lookup hover cards, and mobile record views. This feature is entirely absent.

**Reference Screenshot**: `screenshots/lead-setup/object_lead_tabs.png`

---

#### TC-LEAD-RL01: Related Lists — Configuration vs Actual

**Objective**: Document all Related Lists on Lead detail and their load status

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | Navigate to Lead detail, click "Related" tab | Related Lists visible | Tab clicked successfully | Pass |
| 2 | Record all Related List sections | Lists should load with data or empty state | 5 Related Lists found (see below) | Pass |
| 3 | Check each list's load status | All should load successfully | 1 loaded, 1 error, 3 stuck loading | Fail |

**Related Lists Status**:

| Related List | Status | Detail |
|-------------|--------|--------|
| Cloud User Request | ✅ Loaded | "0" records — "No cloud user request to display" |
| Notes | ❌ Error | "Failed to load related records — entity type AttachedContentNote does not support query" |
| Files | ⏳ Stuck loading | Spinner never completes |
| Lead History | ⏳ Stuck loading | Spinner never completes |
| Campaign History | ⏳ Stuck loading | Spinner never completes |

**Comparison with Salesforce Standard Related Lists for Lead**:

| Salesforce Standard | NexusCRM | Status |
|-------------------|----------|--------|
| Open Activities | ❌ Not present | Missing |
| Activity History | ❌ Not present | Missing |
| Campaign History | ✅ Present | Stuck loading |
| Notes & Attachments | ⚠️ Split into Notes + Files | Notes errors, Files stuck |
| Lead History | ✅ Present | Stuck loading |
| HTML Email Status | ❌ Not present | Missing |
| Cloud User Request | ✅ Present | Custom related list, works |

**Note**: Cannot compare with Setup configuration because Page Layouts API fails (PL01). The related lists shown may be hardcoded defaults rather than layout-configured.

**Reference Screenshot**: `screenshots/lead-setup/detail_related_tab.png`

---

#### TC-LEAD-AP03: Submit for Approval — Actual Click

**Objective**: Verify what happens when "Submit for Approval" is clicked on a Lead with no configured approval process

| Step | Action | Expected Result | Actual Result | Pass/Fail |
|------|--------|-----------------|---------------|-----------|
| 1 | On Lead detail page, click "Submit for Approval" | Dialog or error appears | Submission dialog opened | Pass |
| 2 | Check dialog title | "Submit for Approval" | "Submit for Approval" | Pass |
| 3 | Check dialog description | Explanation of what submission does | "Submit this Lead record for approval. An approver will review and either approve or reject it." | Pass |
| 4 | Check "Next Approver" field | Optional approver selection | "Next Approver (Optional)" with search lookup. Note: "Leave blank to use the standard approval process routing." | Pass |
| 5 | Check Comments field | Optional comments textarea | "Comments (optional)" — present | Pass |
| 6 | Check action buttons | Cancel and Submit | "Cancel" and "Submit for Approval" buttons | Pass |
| 7 | Click Cancel | Dialog closes, no submission | Dialog closed, returned to detail page | Pass |

**Key Observation**: The dialog opens successfully even though no Lead approval process exists (AP01). If user clicks "Submit for Approval", it would likely fail at the backend since there's no process to route to. This was not tested (risk of creating unrecoverable state).

**Reference Screenshot**: `screenshots/lead-setup/submit_for_approval_result.png`

---

## 4. Screenshot Checklist

| # | Description | Filename | Status |
|---|-------------|----------|--------|
| 1 | Lead Object Fields tab (348 fields) | `lead-setup/object_lead_fields.png` | ✅ |
| 2 | Page Layouts tab (error) | `lead-setup/page_layouts_list.png` | ✅ |
| 3 | Validation Rules tab (error) | `lead-setup/validation_rules_list.png` | ✅ |
| 4 | Lead Detail page sections | `lead-setup/detail_no_layout.png` | ✅ |
| 5 | Flows page (Lead flows) | `lead-setup/flows_page.png` | ✅ |
| 6 | Approval Processes page | `lead-setup/approval_processes_page.png` | ✅ |
| 7 | Email Templates page (empty) | `lead-setup/email_templates_page.png` | ✅ |
| 8 | Create form error (Owner + Name) | `lead-setup/c02_create_form_error.png` | ✅ |
| 9 | Edit save 400 error | `lead-setup/e02_save_400_error.png` | ✅ |
| 10 | Object Manager tabs (no Compact Layouts) | `lead-setup/object_lead_tabs.png` | ✅ |
| 11 | Related tab with load statuses | `lead-setup/detail_related_tab.png` | ✅ |
| 12 | Submit for Approval dialog | `lead-setup/submit_for_approval_result.png` | ✅ |

---

## 5. Known Issues Summary

| # | Path | Description | Severity | Related Issue |
|---|------|-------------|----------|---------------|
| 1 | PL01 | Page Layouts fails to load: "Cannot read properties of null (reading 'layouts')" | High | — |
| 2 | VR01 | Validation Rules fails to load: "Cannot read properties of null (reading 'rules')" | High | — |
| 3 | PL02 | Cannot verify layout-to-detail mapping because layout config is unavailable | Medium | Blocked by #1 |
| 4 | PL03 | Edit form shows 292 fields — may be rendering all editable fields instead of layout-configured subset | Medium | Blocked by #1 |
| 5 | PL04 | Column picker "Selected (0)" mismatch with 6 visible columns | Medium | — |
| 6 | VR02 | Only client-side required-field validation observed; no Salesforce-style formula validation rules fire | Info | May be unimplemented |
| 7 | FL02 | Flow behavior cannot be verified — blocked by edit/create bugs | Blocked | #516, #517, #518 |
| 8 | AP01 | No Lead approval processes configured | Info | — |
| 9 | ET01 | No email templates in the environment | Info | — |
| 10 | Detail | HTML entity encoding in field labels: "SDR (NA&amp;EMEA&amp;APAC)" should be "SDR (NA&EMEA&APAC)" | Medium | Related to #516 |
| 11 | CL01 | Compact Layouts tab not implemented in Object Manager | Medium | Unfinished feature |
| 12 | RL01 | Notes related list error: "entity type AttachedContentNote does not support query" | High | — |
| 13 | RL01 | Files, Lead History, Campaign History related lists stuck loading (spinner never completes) | High | — |
| 14 | RL01 | Open Activities and Activity History related lists missing entirely | Medium | — |
| 15 | AP03 | Submit for Approval dialog opens but no approval process exists — submitting would likely fail | Low | — |

---

## 6. Cross-Reference: Setup Findings Explain Runtime Issues

| Runtime Issue (from PR #509) | Root Cause Found |
|------------------------------|-----------------|
| "No page layout assigned" on detail (earlier version) | PL01: Layout API returns null |
| Edit form has 292 fields | PL03: Without layout config, form likely falls back to all editable fields |
| Only 2 related list sections (earlier test) | Current test shows 5 related list quick links — may have been fixed, or earlier test didn't scroll far enough |
| Column picker "Selected (0)" | PL04: No list view configuration saved/loaded |
| E02 Vertical picklist 400 error | Field label encoding: `&amp;` in data (confirmed "Computer Equipment &amp; Peripherals" in detail view) |
| E03 validation works | VR02: Client-side required-field validation works independently of Salesforce validation rules |
| D02 only found 2 related lists (earlier test) | RL01: 5 related lists exist but 3 stuck loading, 1 errors. Earlier test likely saw only the 2 that loaded |
| "Submit for Approval" button purpose unclear | AP03: Dialog opens with approver/comments fields, but no Lead approval process configured |

---

## 7. Recommendations

1. **Fix Layout API** (PL01) — Root cause of multiple rendering issues. The `/describe` or layout endpoint returns null for Lead layouts.
2. **Fix Validation Rules API** (VR01) — Same null pointer pattern. May be the same underlying issue.
3. **HTML entity decoding** — Field labels and picklist values containing `&` are stored/displayed as `&amp;`. Affects both display (cosmetic) and save (functional blocker #516).
4. **Retest after fixes** — Once PL01 and VR01 are fixed, rerun PL02/PL03 to verify layout-to-behavior mapping, and VR02/VR03 to verify server-side validation rules.
5. **Flow verification** — Retest FL02 once Lead create/edit is unblocked.
