Hello friends, today we will discuss the Invocable Method in Apex Salesforce. We use @InvocableMethod annotation on the apex method to invoke this method from the process builder. Without @InvocableMethod annotation, we can’t access the apex method in process builder.
Check this Wrapper class Datatable in LWC Salesforce
Invocable Method Snippets :
public class InvocableCtrl {
@InvocableMethod(label='Update Contact' description='Update the list of contacts')
public static void updateData(List<Id> contactIds) {
}
}
Highlights Points :
- We can use only one @InvocableMethod annotation per class.
- The invocable method must be static and public or global, and its class must be an outer class
- Method should only one parameters
- We can’t use other annotations with the InvocableMethod annotation.
Let’s start with an example :
Step 1: Create an Apex class to update the account name when the Account is inserted.
public class InvocableCtrl {
@InvocableMethod(label='Update Account' description='Update the list of accounts')
public static void updateData(List<Id> accountIds) {
List<Account> accList = new List<Account>();
for(Account acc : [SELECT Id, Name FROM Account WHERE ID IN :accountIds]){
Account ac = new Account();
ac.Id = acc.Id;
ac.Name = ac.Name + '-' + 'Household';
accList.add(ac);
}
if(!accList.isEmpty()){
update accList;
}
}
}
Step 2: Create a Process Builder, click Setup > Process Builder > New

Step 3: Add Object Account and Set execution when only when a record is created

Step 4: Set Criteria, in my case I chose No criteria -just execute the action

Step 5: Select Action Type Apex, set Action Name, select Apex class method Invocable label, and in last set variables

Now Activate the process builder and test the full process by creating an account record and checking account name with household postpend.