Generate optimized Salesforce Lightning Page using proven fieldInstance pattern and AI-guided persona templates
From opspal-salesforcenpx claudepluginhub revpalsfdc/opspal-commercial --plugin opspal-salesforce--object {Object} --persona {persona} --org {org-alias}Generate optimized, persona-based Lightning Pages (FlexiPages), Compact Layouts, and optionally Classic Layouts using AI-powered template engine with intelligent field scoring.
✅ Use this command when:
/analyze-layout recommendations (score <85)sf)/design-layout --object {Object} --persona {persona} --org {org-alias}
/design-layout --object {Object} --detect-persona --org {org-alias}
/design-layout --object {Object} --persona {persona} --org {org-alias} --object-template {template}
--object (REQUIRED): Salesforce object API name
Opportunity, Account, Contact, Lead, Case--persona (REQUIRED unless --detect-persona): Persona template name
sales-rep, sales-manager, executive, support-agent, support-manager, marketing, customer-success--org (REQUIRED): Salesforce CLI org alias
sf org list--detect-persona: Auto-detect persona from current user profile/role
--object-template: Specific object template to use
sales-cloud-default, cpq-enhanced, service-cloud-defaulttemplates/layouts/objects/ for available templates--include-classic: Generate Classic Layout in addition to FlexiPage
--output-dir: Custom output directory
instances/{org}/generated-layouts/{timestamp}/--verbose: Show detailed generation output
Step 1: Persona Selection
--detect-persona: Analyzes user profile/role--persona: Uses specified personaStep 2: Field Scoring
Step 3: Section Generation
Step 4: Component Selection
Step 5: Metadata Generation
Step 6: Quality Validation
Step 7: Save Output
Step 8: Display Results
Location: instances/{org}/generated-layouts/{timestamp}/
Files:
{Object}_{Persona}_FlexiPage.flexipage-meta.xml - Lightning Page{Object}_{Persona}_CompactLayout.compactLayout-meta.xml - Highlights Panel fields{Object}_{Persona}_Layout.layout-meta.xml - Classic Layout (if --include-classic){Object}_{Persona}_generation_summary.json - Metadata + quality analysisDEPLOYMENT_INSTRUCTIONS.md - Step-by-step deployment guideGenerated layouts are automatically analyzed and scored (0-100):
| Score Range | Grade | Assessment | Action |
|---|---|---|---|
| 90-100 | A+, A, A- | Exceptional | Deploy with confidence |
| 85-89 | B+, B | Good | Safe to deploy |
| 80-84 | B- | Above Average | Review recommendations, consider improvements |
| 70-79 | C+, C, C- | Needs Improvement | Apply recommendations, regenerate |
| <70 | D, F | Poor | Significant issues, do not deploy |
Quality Gates:
/design-layout --object Opportunity --persona sales-rep --org my-sandbox --verbose
Expected Output:
🎨 Generating layout for Opportunity (persona: sales-rep)...
✓ Loaded persona template: sales-rep
✓ Retrieved 87 fields for Opportunity
🧮 Scoring fields...
Critical (90-100): 8 fields
Important (75-89): 15 fields
Contextual (50-74): 22 fields
Low Priority (25-49): 28 fields
Minimal (0-24): 14 fields
✓ Generated 4 sections with 45 fields
✓ Selected 9 components:
- Highlights Panel
- Path
- Field Section: Opportunity Information (8 fields)
- Field Section: Additional Details (15 fields)
- Field Section: Supplemental Information (22 fields)
- Activities
- Related List: Contact Roles
- Related List: Quotes
- Related List: Tasks
✓ Generated CompactLayout with 5 fields
✓ Quality validation: 88/100 (B+)
📁 Files saved to:
instances/my-sandbox/generated-layouts/2025-10-18-143522/
- Opportunity_sales_rep_FlexiPage.flexipage-meta.xml
- Opportunity_sales_rep_CompactLayout.compactLayout-meta.xml
- Opportunity_sales_rep_generation_summary.json
- DEPLOYMENT_INSTRUCTIONS.md
💡 Deployment Instructions:
1. Review generated files in output directory
2. Deploy to sandbox using SF CLI or change set
3. Assign to Sales app + Sales Rep profile
4. Test with sales rep user
5. Validate with /analyze-layout command
✓ Complete
/design-layout --object Case --detect-persona --org production
Expected Output:
🎨 Generating layout for Case...
🔍 Detecting persona from current user...
User: support.agent@company.com
Profile: Service Cloud User
Role: Support Agent - Americas
Permission Sets: Service Cloud User, Knowledge User
✓ Detected persona: support-agent (confidence: 95% - HIGH)
Proceeding with support-agent persona...
✓ Loaded persona template: support-agent
✓ Retrieved 112 fields for Case
✓ Generated 5 sections with 68 fields
✓ Selected 11 components including Knowledge and SLA Status
✓ Quality score: 91/100 (A-)
📁 Files saved to:
instances/production/generated-layouts/2025-10-18-150033/
✓ Complete
/design-layout --object Opportunity --persona sales-manager --org cpq-sandbox \
--object-template cpq-enhanced --verbose
Expected Output:
🎨 Generating layout for Opportunity (persona: sales-manager)...
✓ Loaded object template: opportunity/cpq-enhanced.json
✓ Loaded persona template: sales-manager.json
✓ Merging templates...
CPQ-specific fields included:
- SBQQ__QuotePricebookId__c (score: 92 - CRITICAL)
- SBQQ__PrimaryQuote__c (score: 88 - IMPORTANT)
- SBQQ__Contracted__c (score: 85 - IMPORTANT)
- SBQQ__OrderProductBookings__c (score: 82 - IMPORTANT)
✓ Generated 6 sections with 78 fields
✓ Quality score: 86/100 (B)
📁 Files saved to:
instances/cpq-sandbox/generated-layouts/2025-10-18-151245/
✓ Complete
/design-layout --object Account --detect-persona --org hybrid-org
Expected Output:
🎨 Generating layout for Account...
🔍 Detecting persona from current user...
User: partner.manager@company.com
Profile: Partner Community User
Role: Partner Manager
Permission Sets: Partner Access
⚠️ Low confidence persona detection (62% - MEDIUM)
Detected: sales-manager
Alternatives:
- executive (score: 58)
- sales-rep (score: 45)
Recommendation: Confirm persona or specify explicitly
Would you like to:
1. Proceed with 'sales-manager' (recommended)
2. Use 'executive' instead
3. Use 'sales-rep' instead
4. Cancel and specify persona manually
[User selects option 1]
Proceeding with sales-manager persona...
✓ Generated layout
✓ Quality score: 84/100 (B-)
Goal: Migrate Classic layouts to optimized Lightning Pages
Workflow:
# Step 1: Analyze Classic
/analyze-layout --object Opportunity --org production
# Step 2: Generate Lightning
/design-layout --object Opportunity --persona sales-rep --org sandbox
# Step 3: Compare and deploy
Goal: Create different layouts for different user personas
Workflow:
# Sales Rep layout
/design-layout --object Opportunity --persona sales-rep --org sandbox
# Sales Manager layout
/design-layout --object Opportunity --persona sales-manager --org sandbox
# Executive layout
/design-layout --object Opportunity --persona executive --org sandbox
Goal: Create layouts that deploy to any Salesforce org (regardless of Dynamic Forms availability)
Workflow:
/design-layout --object Case --persona support-agent --org service-sandbox --verbose
# Generated layout uses fieldInstance pattern - works in all orgs
Benefits:
Goal: Improve low-scoring existing layout
Workflow:
# Step 1: Analyze existing
/analyze-layout --object Account --org production
# Result: 72/100 (C)
# Step 2: Generate optimized
/design-layout --object Account --persona sales-rep --org sandbox
# Result: 87/100 (B+)
# Improvement: +15 points → Deploy
Symptoms:
❌ Error: Failed to load persona template 'sales-mgr'
Solution:
sales-rep, sales-manager, executive, support-agent, support-manager, marketing, customer-successSymptoms:
❌ Error: Failed to get field metadata for Oportunity
Solution:
__c suffixSymptoms:
⚠️ Quality score: 68/100 (D+)
Top Issues:
1. Too many fields (152 total)
2. Missing Highlights Panel
3. No Dynamic Forms
Solution:
Symptoms:
❌ Error: EACCES: permission denied, mkdir 'instances/...'
Solution:
--output-dir to specify writable locationGenerated layouts include DEPLOYMENT_INSTRUCTIONS.md with specific steps for that layout. General process:
# Copy files to Salesforce project
cp instances/{org}/generated-layouts/{timestamp}/* force-app/main/default/
# Deploy to sandbox
sf project deploy start --source-dir force-app/main/default --target-org {sandbox}
# Assign Lightning Page to app/profile
# (via Setup → Lightning App Builder → Activation)
# Test with target persona user
# After sandbox testing and approval:
# Option 1: Change Set
# Create change set in sandbox, add components, upload to production
# Option 2: SF CLI Deploy (if using SF CLI in production)
sf project deploy start --source-dir force-app/main/default --target-org production
# Validate deployed layout
/analyze-layout --object {Object} --org {deployed-org}
# Should score same or better than generated layout
/analyze-layout/layout-feedback (Phase 4)# Analyze existing layout
/analyze-layout --object Opportunity --org production
# Result: 72/100 (C) - needs improvement
# Generate optimized replacement
/design-layout --object Opportunity --persona sales-rep --org sandbox
# Result: 88/100 (B+) - ready to deploy
# Generate layout
/design-layout --object Case --persona support-agent --org sandbox
# Validate generation
/analyze-layout --object Case --org sandbox
# Deploy (Phase 3 feature - not yet available)
/deploy-layout --object Case --org sandbox --validate-only
Phase 2 does NOT include automatic deployment:
Automatic deployment comes in Phase 3.
Generates layouts from existing fields only:
Field scoring without org-specific usage data:
Cannot preview layout before deployment:
All generated layouts must meet:
When this command is invoked, delegate to the sfdc-layout-generator agent:
Task: Invoke sfdc-layout-generator agent with parameters:
- Object: {object}
- Persona: {persona or auto-detect}
- Org: {org}
- Object Template: {object-template or default}
- Include Classic: {include-classic flag}
- Output Directory: {output-dir or default}
- Verbose: {verbose flag}
Expected Deliverables:
1. FlexiPage metadata XML
2. CompactLayout metadata XML
3. Classic Layout metadata XML (if --include-classic)
4. Generation summary JSON
5. Deployment instructions Markdown
6. Quality analysis report
Success Criteria:
- Generation completes successfully
- Quality score ≥85 (B or better)
- All metadata files valid and deployment-ready
- Files saved to output directory
- Deployment instructions provided
Command Version: 2.0.0 Last Updated: 2025-10-18 Pattern Version: fieldInstance v2.0.0 (replaces Dynamic Forms v1.0) Part of: salesforce-plugin v3.13.0 (Layout Designer Phase 2)
Changelog v2.0.0: