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

Reducing Operational Costs with AI Chatbots: A Smart Business Move featured image
December 29, 2025
Operational costs often rise because teams spend too much time on repetitive, low-value work. This article explains how AI chatbots reduce those costs by deflecting routine requests, shortening support interactions, automating back-and-forth workflows, and allowing businesses to scale without hiring linearly. It also shows how Anablock designs cost-effective AI chatbot solutions that deliver measurable automation savings while improving customer experience.
Cross-Industry Applications of AI Chatbots featured image
December 23, 2025
AI chatbots are no longer limited to basic FAQs. This article explores how the same conversational AI technology is being applied across healthcare, real estate, finance, hospitality, e-commerce, SaaS, and internal operations. You will see practical examples of how businesses use chatbots to automate repetitive tasks, improve responsiveness, and connect systems across industries, along with guidance on choosing the right starting use case.
10 CRM Admin Tasks You Should Automate with AI featured image
December 22, 2025
If being a CRM admin feels like nonstop cleanup, this article is for you. It breaks down ten time consuming CRM admin tasks that can be automated with AI, from deduplication and data enrichment to workflow monitoring and documentation. You will see how AI shifts CRM administration from manual maintenance to intelligent system design, and how Anablock helps make that transition practical and safe.

Unlock the Full Power of AI-Driven Transformation

Schedule Demo

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

Book Demo

Start a Support Agent

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

Call Now

Send us a Message

Summarize this page content with AI