GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] New Rule: Avoid Future Annotation · Issue #6203 · pmd/pmd

[apex] New Rule: Avoid Future Annotation #6203

New issue
Copy link
New issue
Copy link
Closed
#6204
Closed
[apex] New Rule: Avoid Future Annotation#6203
#6204
Copy link
Labels
a:new-ruleProposal to add a new built-in rule
Milestone
7.19.0

Description

@mitchspano
mitchspano
opened on Nov 4, 2025
Issue body actions

Proposed Rule Name: AvoidFutureAnnotation

Proposed Category: Best Practices

Description:

The @Future annotation is a legacy way to execute asynchronous Apex code in Salesforce. While it still works, it has several limitations that make it less suitable for modern Apex development:

  • Methods must be static
  • Only primitive data types, primitive arrays, or collections of primitive data types can be parameters
  • No way to monitor job status or handle failures
  • No support for chaining jobs

The Queueable interface provides a more modern and flexible alternative that addresses these limitations:

  • Better error handling and monitoring capabilities (via Transaction Finalizers)
  • Support for more complex data types (including custom classes and collections of sObjects)
  • Ability to chain jobs together

This rule flags usage of the @Future annotation and suggests implementing the Queueable interface instead.

Code Sample::

// Not recommended: Using @Future annotation
public class FutureExample {
    @Future
    public static void futureMethod(String accountId) {
        // Process account asynchronously
        Account acc = [SELECT Id, Name FROM Account WHERE Id = :accountId];
        // ... process account
    }
}

// Recommended: Using Queueable interface
public class QueueableExample implements Queueable {
    private String accountId;

    public QueueableExample(String accountId) {
        this.accountId = accountId;
    }

    public void execute(QueueableContext context) {
        Account acc = [SELECT Id, Name FROM Account WHERE Id = :accountId];
        // ... process account
    }
}

// Usage:
// System.enqueueJob(new QueueableExample(accountId));

Possible Properties:

  • Should this rule be customizable via properties?

No properties are needed at this time.

Reacted by Daniel Ballinger, Piotr Kożuchowski and Szymon Halik

Activity

  1. mitchspano
    added
    a:new-ruleProposal to add a new built-in rule
    on Nov 4, 2025
  2. FishOfPrey commented on Nov 4, 2025

    @FishOfPrey
    FishOfPrey
    on Nov 4, 2025
    More actions

    Queueable jobs also offer more controls for deduplication of workloads and delayed execution.
    We have consistent guidance in the Architecture Center for Tools for Asynchronous Processing with Salesforce for using Queueables in preference to future methods.

  3. mitchspano
    changed the title [-][apex] Avoid Future Annotation[/-] [+][apex] New Rule: Avoid Future Annotation[/+] on Nov 5, 2025
  4. Bukama commented on Nov 17, 2025

    @Bukama
    Bukama
    on Nov 17, 2025
    More actions

    Please be aware there are several annotations which are called @Future, for example Jakarta EE's @Future which has nothing to do with asynchronous execution, but with validation.

  5. mitchspano commented on Nov 17, 2025

    @mitchspano
    mitchspano
    on Nov 17, 2025
    ContributorAuthor
    More actions

    @Bukama this rule is for Apex, not Java.

    Reacted by Matthias Bünger
  6. adangel
    added this to the 7.19.0 milestone on Nov 20, 2025
  7. adangel
    added a commit that references this issue on Nov 20, 2025

    [doc] Update release notes (#6203, #6204)

    26c17b2
  8. adangel
    closed this as completedin #6204on Nov 20, 2025
  9. jtferns commented on Jan 8, 2026

    @jtferns
    jtferns
    on Jan 8, 2026
    More actions

    🙋 @mitchspano we just stumbled into this on recent code-analyzer runs, and have been wondering what's the best way to address Mixed DML scenarios in Apex test setups; the docs still suggests using @future; should it suggest Queueable instead?

    (I scoured a few other SF repos to figure out where to ask/drop an issue, but couldn't find an obvious one; this is definitely not an issue with pmd, and is more relevant for Apex/testing; happy to be redirected elsewhere)

  10. mitchspano commented on Jan 14, 2026

    @mitchspano
    mitchspano
    on Jan 14, 2026
    ContributorAuthor
    More actions

    @jtferns Yes, Queueable should be used instead of @Future.
    Thanks for sharing the reference to the docs, I will share with our document team and get that updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-ruleProposal to add a new built-in rule

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.19.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.