Activity Forums Salesforce® Discussions What is the use of the invocable method annotation in Salesforce?

  • Anjali

    Member
    August 20, 2018 at 11:19 am

    Hi Avnish,

    Invocable Method annotation used to identify methods that can be run as invocable actions.
    Invocable methods are called with the REST API and used to invoke a single Apex method. Invocable methods have dynamic input and output values and support describe calls.

     

  • shariq

    Member
    September 16, 2018 at 9:44 am

    Hi,

    To add more -

    There can be at most one input parameter and its data type must be one of the following:

    • A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
    • A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported.
    • A list of a user-defined type, containing variables of the supported types and with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.

    Hope this helps.

  • Parul

    Member
    September 21, 2018 at 9:47 pm

    Adding some points:

    While the Process builder is very flexible out of the box, there are a few business use cases those are not achievable using it. For example

    1. It doesn’t support outbound messages
    2. It doesn't support creation of multiple records
    3. It doesn’t allow us to delete a record

    When no other process action can get the job done, add customized functionality to your Salesforce processes by calling an Apex method. To call an Apex method, add the Call Apex action to your process and select an Apex class with an @invocable method Annotation. It means they allow us to extend the Process Builder by writing Apex code that meets certain criteria, and then invoking the Apex from our Processes. If the class contains one or more invocable variables, manually enter values or reference field values from a related record. @InvocableMethod Annotation support bulk operations.

    public class DeleteUnacceptedQuotes
    {
    @InvocableMethod
    public static void QuoteDelete(List<Id> OpportunityIds)
    {
    List<Quote> Quotes =[select id from quote
    where Opportunity.id in :OpportunityIds
    and Status != 'Accepted'];
    delete Quotes;
    }
    }

     

    Thankz

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos