@InvocableMethod Annotation
I’m using the @InvocableMethod annotation in my Apex class to allow a Flow to update accounts, but I’m encountering an issue when trying to pass multiple input parameters. Salesforce is throwing an error saying, “Methods defined with @InvocableMethod must have a single parameter of type List.” How can I structure my method to accept multiple parameters, such as account names and industries, while adhering to the @InvocableMethod constraints? Here’s the code I’m working with during my Salesforce training in India, which isn’t functioning as expected:
Code:
public with sharing class AccountUpdater {
@InvocableMethod
public static void updateAccounts(String accountName, String accountIndustry) { // Error: Multiple parameters not allowed
List<Account> accountsToUpdate = [SELECT Id FROM Account WHERE Name = :accountName];
for (Account acc : accountsToUpdate) {
acc.Industry = accountIndustry;
}
update accountsToUpdate;
}
}
How can I modify this code to meet the requirements of the @InvocableMethod annotation?