10 Best Salesforce Coding Prompt Templates for Vibe Coding: The Developer’s Ultimate Cheat Sheet

10 Best Salesforce Coding Prompt Templates for Vibe Coding: The Developer’s Ultimate Cheat Sheet

Below are 10 reusable Vibe Coding Prompt Templates for Agentforce Vibes that serve as a foundation for developers. Each template follows Salesforce’s official prompt structure and includes placeholders (in [brackets]) so developers can customize them easily.

Universal Prompt Structure for Vibe Coding

Every effective prompt should include these 6 components:

ComponentWhat to IncludeExample
RoleWho should AI act as?“You are an experienced Salesforce developer…”
ContextWhat are you building?“…building an FSC loan origination solution…”
GoalDesired outcome“Create an Apex class that…”
ConstraintsBest practices & limits“Bulkified, 90% coverage, no hard-coded IDs”
DataObject/field details“Custom object Loan_Application__c…”
StyleFormat & tone“Include ApexDocs comments, ES6+ syntax”

10 Reusable Prompt Templates

Template 1: Apex Trigger Handler

You are an experienced Salesforce developer building a [FINANCIAL_SERVICES/INDUSTRY] solution.

Create an Apex trigger handler class named [CLASS_NAME] following Salesforce best practices:

**Requirements:**
- Bulkified code (no SOQL/DML in loops)
- Logic in handler, not trigger (trigger should be empty)
- Support events: [BEFORE_INSERT, AFTER_INSERT, BEFORE_UPDATE, AFTER_UPDATE, BEFORE_DELETE, AFTER_DELETE]
- Object: [OBJECT_API_NAME]
- Include inline comments explaining each method
- Use ApexDocs comments for class/method documentation
- Add @future or Queueable for async operations if needed

**Output Format:**
- Complete Apex class with all methods
- Include trigger file (empty trigger calling handler)
- Add inline comments for each business logic section

Template 2: Lightning Web Component (LWC)





You're working on a [PROJECT_NAME] implementation for [INDUSTRY/CLIENT_TYPE].

Write a Lightning Web Component that [DISPLAYS/PROCESSES/CREATE] [DATA_TYPE] from [OBJECT_API_NAME].

**Requirements:**
- Use @wire for SOQL queries (imperative SOQL only if DML needed)
- Display in [DATATABLE/FORM/CARD/LIST] with [SEARCH/FILTER/PAGINATION]
- Object fields: [FIELD1__c, FIELD2__c, FIELD3__c]
- Follow LWC security best practices (no SOQL injection, encodeOutput)
- Use modern ES6+ syntax only (no Aura components)
- Include CSS for responsive design
- Add JavaScript controller logic for [ACTION_TYPE]
- Include HTML template with proper accessibility (ARIA labels)

**Output Format:**
- JavaScript file (.js)
- HTML template (.html)
- CSS file (.css)
- XML metadata file (.xml)
- Apex @AuraEnabled method if server-side call needed

Template 3: Bulkified SOQL Query Pattern





Generate a bulkified SOQL query pattern for querying [NUMBER] records of [OBJECT_API_NAME] with related [RELATED_OBJECTS] data.

**Requirements:**
- Use relationship queries to avoid SOQL in loops
- Selective WHERE clauses using indexed fields: [INDEXED_FIELD1, INDEXED_FIELD2]
- Avoid SELECT * (specify exact fields)
- Include LIMIT and ORDER BY for performance
- Handle null/empty results gracefully
- Add comments explaining query optimization choices
- Include Apex code showing how to use query results in bulk context

**Below are the fields needed:**
- Parent object: [OBJECT_API_NAME] with fields [FIELD_LIST]
- Child objects: [CHILD_OBJECT_1, CHILD_OBJECT_2]
- Filter criteria: [WHERE_CONDITIONS]

**Output Format:**
- Complete SOQL query string
- Apex method showing bulk usage pattern
- Performance notes for large data volumes (>10K records)

Template 4: Apex Batch Class for Data Operations





Create an Apex batch class named [BATCH_CLASS_NAME] with these specifications:

**Requirements:**
- Implements Database.Batchable<SObject> and Database.Stateful
- Scope size: [SCOPE_SIZE] records (default: 200)
- Includes start(), execute(), and finish() methods
- Implements error handling with try-catch in execute()
- Logs processing status in custom object [LOG_OBJECT_NAME__c]
- Includes [COMPOSITE/QUEUEABLE] interface for custom transformations if needed
- Uses Database.DatabaseResult for partial success handling
- Includes customizable queryLocator in start()

**Business Logic:**
- Process: [OPERATION_TYPE] on [OBJECT_API_NAME]
- Fields to update: [FIELD1__c, FIELD2__c]
- Filter criteria: [WHERE_CONDITIONS]
- Error handling: [ERROR_LOGGING_METHOD]

**Output Format:**
- Complete batch class with all methods
- Custom log object field definitions (if needed)
- Example of how to execute the batch
- Test class stub with @TestSetup

Template 5: Platform Event Subscriber/Handler





You are building a [REAL_TIME/AUTOMATED] [BUSINESS_PROCESS] system.

Create a Platform Event subscriber class for [EVENT_NAME__e]:

**Requirements:**
- Implements Messaging.StreamingHandler
- Handles subscribe/unsubscribe methods
- Processes event payload safely (validate schema)
- Includes error logging to [LOG_OBJECT__c]
- Uses PushNotifications for UI updates if needed
- Handles replay ID for message persistence
- Includes Apex callout if external system integration needed

**Event Details:**
- Event name: [EVENT_NAME__e]
- Payload fields: [FIELD1__c, FIELD2__c, FIELD3__c]
- Triggered by: [TRIGGER_EVENT]
- Action to take: [ACTION_ON_RECEIPT]

**Output Format:**
- Complete subscriber class
- Subscribe method with CometD configuration
- Error handling and logging utilities
- Example of publishing the event (if needed)

Template 6: REST API Integration Class





Create an Apex REST service class named [CLASS_NAME] that [EXPOSES/CONSUMES] [DATA_TYPE] via REST API.

**If Exposing REST API:**
- Use @RestResource(urlMapping='/[ENDPOINT_PATH]/*')
- Implements GET/POST/PUT/DELETE with @HttpGet, @HttpPost, @HttpPut, @HttpDelete
- Validates input using Schema.Describe or custom validation
- Returns JSON responses with proper HTTP status codes (200, 201, 400, 404, 500)
- Follows OAuth 2.0 authentication patterns
- Includes rate limiting and audit logging

**If Consuming REST API:**
- Uses Http class with HttpRequest/HttpResponse
- Implements OAuth 2.0 JWT bearer flow or Named Credentials
- Parses JSON response using JSON.deserializeUntyped()
- Includes retry logic with exponential backoff
- Handles connection timeouts and errors

**Integration Details:**
- Object: [OBJECT_API_NAME]
- Fields: [FIELD1__c, FIELD2__c]
- Authentication: [AUTH_METHOD]
- External system: [SYSTEM_NAME]
- Endpoint: [API_URL]

**Output Format:**
- Complete Apex REST class
- OR consumer class with Named Credentials setup
- JSON request/response examples
- Error handling utilities

Template 7: FSC-Specific Financial Logic





You are an FSC specialist building [CLIENT_RELATIONSHIP/LOAN_ORIGINATION/WEALTH_MANAGEMENT] features.

Create an Apex class named [CLASS_NAME] that [ACTION] using Financial Services Cloud standard objects.

**Requirements:**
- Uses FSC standard objects: [FINANCIAL_ACCOUNT, FINANCIAL_CONTACT_ROLE, PERSON_ACCOUNT, etc.]
- Implements [LOGIC_TYPE]: aggregation, calculation, validation, workflow
- Calculates: [METRIC_1, METRIC_2, METRIC_3] (e.g., total assets, liabilities, net worth)
- Includes @AuraEnabled methods for LWC consumption
- Follows FSC data model best practices (use relationship queries, not child-to-parent in loops)
- Handles [PERSON_ACCOUNT/BUSINESS_ACCOUNT] scenarios
- Includes FSC-specific field sets if applicable

**Business Logic:**
- FinancialAccount: [ACCOUNT_TYPE]
- Contact roles: [ROLE_TYPE]
- Products: [LOAN/INSURANCE/INVESTMENT]
- Output: [SUMMARY_REPORT/DASHBOARD_DATA/VALIDATION_RESULT]

**Output Format:**
- Complete Apex class with @AuraEnabled methods
- FSC object field references with API names
- Example LWC usage snippet
- Test data setup using FSC standard records

Template 8: Comprehensive Test Class





Generate a comprehensive Apex test class named [TEST_CLASS_NAME] for [CLASS_OR_TRIGGER_NAME].

**Requirements:**
- Achieve [PERCENTAGE]%+ code coverage (default: 95%)
- Test all trigger events/methods: [LIST_OF_METHODS_OR_EVENTS]
- Include positive test cases (valid data)
- Include negative test cases (invalid data, exceptions)
- Use Test.startTest() and Test.stopTest() for async code
- Use System.assert() or System.assertEquals() for validation
- Create test data using @TestSetup method (single setup for all tests)
- Use Test.setDataCategoryLevelAccess() if content categories used
- Test bulk operations (200+ records)
- Include Test.setMock() if callouts present

**Class/Trigger Details:**
- Object: [OBJECT_API_NAME]
- Methods to test: [METHOD1, METHOD2, METHOD3]
- Exception types: [EXCEPTION_1, EXCEPTION_2]
- Bulk scenarios: [BULK_SIZE] records

**Output Format:**
- Complete test class with @isTest annotation
- @TestSetup method with all required test data
- Individual test methods with descriptive names
- Comments explaining each test scenario
- Coverage report instructions

Template 9: Error Handling & Logging Framework





Create a custom error handling and logging framework for Salesforce.

**Requirements:**

**Custom Object: Error_Log__c**
- Fields:
  - Error_Message__c (Long Text Area)
  - Stack_Trace__c (Long Text Area)
  - User__c (Lookup to User)
  - Severity__c (Picklist: Info, Warning, Error, Critical)
  - Context__c (Text - class/method name)
  - Is_Resolved__c (Checkbox)
  - Resolved_Date__c (Date/Time)

**Apex Utility Class: ErrorHandler**
- Static methods:
  - logError(Exception e, String context)
  - logInfo(String message, String context)
  - getRecentErrors(Integer days)
  - markAsResolved(Integer logId)
  - sendAlertToAdmins(Integer errorId)
- Integration with Platform Events for real-time alerts: [EVENT_NAME__e]
- Follows enterprise logging patterns (no System.debug in prod)
- Includes configurable logging levels

**Additional Features:**
- Batch job to archive old logs (older than [NUMBER] days)
- LWC dashboard to view recent errors
- Email alert to admins on Critical errors

**Output Format:**
- Custom object field definitions (XML or DEploy instructions)
- Complete ErrorHandler utility class
- Platform event publisher method
- LWC snippet for error dashboard (optional)

Template 10: Custom Coding Standard (Slash Command)





/newrule Create a system-level prompt that aligns Agentforce Vibes with my team's coding standards:

**My Coding Standards:**
- Always use [TRIGGER_HANDLER/SERVICE_LAYER/REPOSITORY] pattern
- Bulkify all SOQL/DML (no loops)
- Use ApexDocs comments for all classes/methods
- [PERCENTAGE]%+ test coverage minimum (default: 90%)
- No hard-coded IDs (use custom metadata or labels)
- Follow Salesforce security guidelines (with sharing, encodeOutput)
- Use [FSC_STANDARD_OBJECTS/CUSTOM_METADATA]优先 over hardcoded values
- Use Queueable instead of @future for complex async
- NAMING_CONVENTION: [PascalCase for classes, camelCase for methods]
- FILE_SIZE_LIMIT: Max [NUMBER] lines per class

**Industry-Specific Rules:**
- Industry: [FINANCIAL_SERVICES/HEALTHCARE/RETAIL]
- Compliance: [GDPR/HIPAA/PCI-DSS]
- Data retention: [NUMBER] days
- Encryption: [FIELD_LEVEL_ENCRYPTION/Custom]

**Output Format:**
- Complete /newrule system prompt
- Checklist for developers to verify compliance
- Example of non-compliant vs compliant code

Prompt Best Practices Cheat Sheet

DODON’T
✅ Be specific about objects/fields❌ Say “write code for loans”
✅ Include constraints (bulkified, coverage)❌ Assume AI knows your standards
✅ Specify output format (files, methods)❌ Accept vague responses
✅ Use role-playing (“You are an FSC expert”)❌ Skip context entirely
✅ Iterate: refine prompts based on output❌ Give up after one attempt

How to Use These Templates

  1. Copy the template that matches your task
  2. Replace [PLACEHOLDERS] with your specific details
  3. Add industry/object-specific constraints
  4. Run in Agentforce Vibes (CLI or VS Code extension)
  5. Review output and refine prompt if needed
  6. Save successful prompts as your team’s /newrule standards

Pro Tips for Team Adoption

  1. Create a Prompt Library in your org’s Wiki/Confluence
  2. Add /newrule template to Agentforce Vibes for team-wide consistency
  3. Use scratch orgs to get 50 more requests/org (250/day total)
  4. Enable deep-planning mode (/deep-planning) for complex features
  5. Disable Vibes in production for security compliance

Save these templates as a Markdown file in your team’s repository:

/salesforce-prompt-templates/
├── apex-trigger-handler.md
├── lwc-component.md
├── batch-class.md
├── platform-event.md
├── rest-api.md
├── fsc-financial-logic.md
├── test-class.md
├── error-handling.md
└── coding-standards.md

Subscribe to “FINSforce” for complete Financial Services Cloud (FSC) video tutorials!

For more trips & trick click here

Leave a Reply

Your email address will not be published. Required fields are marked *