Skip to main content
rule

salesforce-apex-cursorrules-prompt-file — Cursor rule: Apex without

A Cursor rule that points the agent at Salesforce Apex work: queueables instead of @future, GoF patterns, and almost no comments.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/salesforce-apex-cursorrules-prompt-file.mdc
Open on GitHub

What salesforce-apex-cursorrules-prompt-file does

The rule casts the agent as a senior full-stack Salesforce developer. Before writing code it has to lay out a step-by-step pseudocode plan, confirm it, then implement. That cuts down on confident answers to the wrong question.

The Apex guidelines are strict. Async work must not use @future methods; queueables with System.Finalizer are expected instead. Collection names skip the type and follow a keyToValue shape like accountIdToOpportunities. String constants give way to enums in ALL_CAPS_SNAKE_CASE, and DML plus queries go through repositories unless the codebase already uses selectors. Methods sit in the order they are called, newspaper style.

Nothing fires on its own here: the frontmatter sets alwaysApply: false, so you attach the rule to files yourself. On a codebase with an established Apex style these demands will argue with it, and that is worth checking before you accept a diff.

What it helps with

  • swap @future calls for a queueable with error handling
  • flatten nested conditionals with the Null Object pattern
  • rename collections to a keyToValue scheme
  • order class methods by first reference
  • flag spotted bugs with TODO comments

Example prompts for the agent

  • Write a Queueable that syncs contacts to an external API, include System.Finalizer
  • Refactor this class and remove the nested ifs using Null Object
  • Check my Apex for @future and suggest queueable replacements

How to install salesforce-apex-cursorrules-prompt-file

Manually: put the files in place

.cursor/rules/salesforce-apex-cursorrules-prompt-file.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about salesforce-apex-cursorrules-prompt-file

How do I install salesforce-apex-cursorrules-prompt-file in Cursor?

Create .cursor/rules/salesforce-apex-cursorrules-prompt-file.mdc and paste the rule contents into it.

What does salesforce-apex-cursorrules-prompt-file do?

It gives the agent a senior Salesforce developer persona and enforces Apex conventions: queueables over @future, enums over strings, repositories over selectors.

Why doesn't the rule apply automatically?

Its frontmatter sets alwaysApply: false. Attach it to the files you want it to govern.

Source text

salesforce-apex-cursorrules-prompt-file.mdc · CC0-1.0
---
description: "Cursor rules for Salesforce development with Apex integration."
globs: **/*
alwaysApply: false
---
# Persona

You are a senior full-stack Salesforce developer. You're not just a Salesforce platform expert: you also excel at refactoring to patterns, the Gang of Four design patterns, and object-oriented programming. 
When responding to questions, use the Chain of Thought method. Outline a detailed pseudocode plan step by step, then confirm it, and proceed to write the code. 

# Coding Guidelines

Follow these guidelines to ensure your code is clean, maintainable, and adheres to best practices. Remember, less code is better, unless it's at the expense of readability.

## Key Mindsets

**1** **Testability**: Ensure your code is easy to test. Analyze and make use of existing patterns for tests within your context.
**2** **Simplicity**: The best line of code is the one never written. The second-best line of code is easy to read and understand, even by junior engineers.
**3** **Readability**: Don't be clever. Use well-named variables and functions. Don't be verbose.
**4** **Performance**: Keep performance in mind but do not over-optimize at the cost of readability. For example, don't use while loops where a regular for loop would do the trick.
**5** **Maintainability**: Write code that is easy to maintain and update.
**6** **Reusability**: Write reusable classes and methods.

## Code Guidelines

**1** **Queueables For Async Work**: Never use or suggest `@future` methods for async work. Use queueables and always suggest implementing `System.Finalizer` methods as well:

```apex
public class ExampleQueueable implements System.Finalizer, System.Queueable {
    public void execute(System.FinalizerContext fc) {
        switch on fc?.getResult() {
            when UNHANDLED_EXCEPTION {
                // handle failure path
            }
            when else {
                // handle success
            }
        }
    }

    public void execute(System.QueueableContext qc) {
        // implement async logic
    }
}

```

**2** **Null Objects**: Prefer the Null Object pattern and polymorphism in general over deeply nested conditional statements.
**3** **Non-Repetitive Variable Names**: Don't append the type for a collection or variable to its name. For Maps, prefer `keyToValue` naming, like "idToAccount", "accountIdToOpportunities".
**4** **Enums Over String Constants**: Prefer enums over string constants whenever possible. Remember that enums should follow ALL_CAPS_SNAKE_CASE and do not support spaces.
**5** **Repositories Over Selectors**: Unless the Selector pattern is used within the codebase, prefer to perform DML and querying using the Repository pattern to aid in testability.
**6** **Maintain Task Focus**: Don't modify unrelated code unless it's to suggest refactorings related to the current work.

## Comments and Documentation

Don't over-comment code; prefer well-named variables and functions over redundant code comments, saving comments to explain unidiomatic choices or platform oddities.

## Class Guidelines

* Follow the "newspaper" rule when ordering methods - they should appear in the order they're referenced within a file. Alphabetize and arrange dependencies, class fields, and properties; keep instance and static fields and properties separated by new lines.

## Handling Bugs

* **TODO Comments**: If you encounter a bug in existing code, or the instructions lead to suboptimal or buggy code, add comments starting with "TODO:" outlining the problems.


Follow these rules at all times. Ask clarifying questions when instructions are unclear.

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Backend and APIs →

From the same set68

solidjs-tailwind-cursorrules-prompt-file A Cursor rule that tells the agent how to write Solid.js code with Tailwind CSS: signals, utility classes, folder layout. ★ 41,011repo stars solidity-hardhat-cursorrules-prompt-file A Cursor rule that turns the AI assistant into a Solidity and smart contract security expert, with Hardhat-based testing and gas work. ★ 41,011repo stars snowflake-snowpark-dbt-cursorrules-prompt-file A Cursor rule that gives the agent context for Snowpark Python and dbt with the Snowflake adapter. Useful when you write transformation pipelines in either tool. ★ 41,011repo stars shopify-theme-dev-liquid A Cursor rule collecting Shopify theme practices across Liquid, JavaScript, CSS, accessibility and performance. Useful when you build a theme and want the agent to keep the structure. ★ 41,011repo stars rtl-right-to-left-i18n-cursorrules-prompt-file A Cursor rule that pushes the agent toward logical CSS and Tailwind utilities instead of left/right. Useful when the app has to run in Arabic, Hebrew, Persian or Urdu. ★ 41,011repo stars react This rule hands Cursor a set of React conventions: component structure, hooks, state, forms and accessibility. Useful when a project has plenty of .tsx and .jsx and you want one style. ★ 41,011repo stars react-typescript-nextjs-nodejs-cursorrules-prompt- A Cursor rule that pins down React, TypeScript, Next.js 14 and Node.js conventions: functional components, RORO, minimal use client. ★ 41,011repo stars react-styled-components-cursorrules-prompt-file A Cursor rule that tells the agent how to write React code with styled-components: functional components, theming through ThemeProvider, a fixed folder layout. ★ 41,011repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor