Salesforce Apex Annotations

Himanshu Varshney
Senior Salesforce Developer
January 19, 2024

HimanshuBlkogpost

@AuraEnabled

Purpose: Makes a method accessible from a Lightning component.

Example:


public class MyController {
    @AuraEnabled
    public static String sayHello(String name) {
        return 'Hello ' + name;
    }
}


@Deprecated

Purpose: Indicates that a method or class should no longer be used.

Example:


public class OldClass {
    @Deprecated
    public static void oldMethod() {
        // Old implementation
    }
}


@Future

Purpose: Marks a method that runs asynchronously.

Example:

public class AsyncProcessor {
    @Future
    public static void processAsync() {
        // Asynchronous processing
    }
}
@InvocableMethod

Purpose: Allows a method to be called from a Process Builder or Flow.
Example:
apex
Copy code
public class FlowController {
    @InvocableMethod
    public static void processRecords(List<Id> recordIds) {
        // Process logic
    }
}


@InvocableVariable

Purpose: Used within a class that has @InvocableMethod to define variables that can be set from a Flow or Process Builder.

Example:

public class Parameters {
    @InvocableVariable
    public String param1;
}


@IsTest

Purpose: Marks a class or method as a test class or test method.

Example:

@IsTest
private class TestMyClass {
    @IsTest static void testMyMethod() {
        // Test code
    }
}


@JsonAccess

Purpose: Allows non-public members of Apex classes to be serialized and deserialized in JSON.

Example:


public class MyClass {
    @JsonAccess
    private String myField;
}


@NamespaceAccessible

Purpose: Exposes a global class, method, or variable to any Apex code that resides in a namespace.

Example:

@NamespaceAccessible
public class SharedClass {
    // Class implementation
}


@ReadOnly

Purpose: Allows a Visualforce page to perform read-only operations that do not count against the governor limits for SOQL queries.

Example:

@ReadOnly
public with sharing class MyReadOnlyClass {
    // Query logic
}


@RemoteAction

Purpose: Exposes a method in a Visualforce controller to be called from JavaScript.

Example:


public with sharing class MyController {
    @RemoteAction
    public static String performAction(String param) {
        // Action logic
    }
}


@SuppressWarnings

Purpose: Instructs the compiler to suppress specific warnings.

Example:


@SuppressWarnings('deprecation')
public class MySuppressedClass {
    // Code that uses deprecated methods
}


@TestSetup

Purpose: Used in test classes to define methods that set up test data.

Example:


@IsTest
private class MyTestClass {
    @TestSetup
    static void setup() {
        // Setup test data
    }
}


@TestVisible

Purpose: Allows test methods to access private or protected members of another class.

Example:

public class MyClass {
    @TestVisible private static Integer myCounter = 0;
}

Each of these annotations serves a specific purpose and helps define the behavior of your Apex code in different scenarios, particularly in the context of Salesforce's multi-tenant environment and its governor limits.

Share this article:
View all articles

Related Articles

The Automation Impact on Response Time and Conversions Is Bigger Than Most Businesses Realize featured image
December 9, 2025
This blog explains how response time has become one of the strongest predictors of conversions and why most businesses lose revenue not from poor marketing, but from slow follow up. It highlights how automation eliminates the delays that humans cannot avoid, ensuring immediate engagement across chat, voice, and form submissions. The post shows how automated systems capture intent at its peak, create consistent customer experiences, and significantly increase conversion rates by closing the gap between inquiry and response. Automation does not just improve speed. It transforms how the entire pipeline operates.
The Silent Power of AI Agents: What Businesses Miss While Focusing Only on Speed featured image
December 1, 2025
Companies usually adopt AI agents for faster responses, but speed is only part of the value. The real advantage comes from consistency. AI agents eliminate human drift by delivering the same accuracy and structure in every interaction, at every hour, without variation. This creates predictable workflows, higher quality early stage interactions, and greater stability across support, sales, and service operations. The post highlights how AI agents enhance performance by reducing variability, supporting teams, and creating long term operational discipline.
Automation Is Not About Saving Time. It Is About Eliminating Friction. featured image
November 27, 2025
Automation is not primarily about saving time. It is about removing the invisible friction that slows down entire organizations. Manual tasks such as follow ups, routing, reminders, data entry, and scheduling drain attention and create gaps where revenue is lost. Automation closes these gaps, removes delays, and allows people to focus on judgment and creative work. The post argues that automation has become core infrastructure for modern businesses because it eliminates friction and creates clarity, consistency, and predictable growth.

Unlock the Full Power of AI-Driven Transformation

Schedule a Demo

See how Anablock can automate and scale your business with AI.

Book Now

Start a Voice Call

Talk directly with our AI experts and get real-time guidance.

Call Now

Send us a Message

Summarize this page content with AI