How to call an APEX Class from a Screen-Flow

By | December 30, 2021

In this blog, we will discuss on how to invoke an Apex class from a Screen Flow through an simple example. In this example, we have created a Screen Flow in which we have created three variables. First one is recordId which is set as available for Input and Output both.

RecordId Variable
RecordId Variable

The second variable that we have created is the Account to store Account Data.

Account Variable
Account Variable

The third variable that we have created is Name. That stores the return value of the Apex class called in the flow.

Name Variable
Name Variable

Then we create an Invocable method in class InvokeAccountAction.apxc which will be called through the Screenflow to return the Name of an particular Account as follows:

public class InvokeAccountAction 
{
  @InvocableMethod(callout=true label='Get Account Name')    
  public static List<String> getAccountNames(List<ID> ids) {
    List<String> accountNames = new List<String>();
    List<Account> accounts = [SELECT Name FROM Account WHERE Id in :ids];
    for (Account account : accounts) {
      accountNames.add(account.Name);
    }
    return accountNames;
  } 
}

Meanwhile, to call the Apex class from the flow we create an Apex action in the flow as shown in the image below:

Apex Action
Apex Action

For example, after calling an Apex class we want to make sure that the return value against the field Name of the particular Account is not empty.

Check return value
Check return value

After that, we create a screen to show the name of that Account, if the condition is satisfied.

Edit Screen
Edit Screen

Likewise, the whole flow can be built as shown in the image below:

ScreenFlow
ScreenFlow

Likewise, after you have completed built the flow you can create a Button Invoke Method to call the flow:

Account Screen with Invoke Method Button
Account Screen with Invoke Method Button

After execution of the flow, we get a Screen which shows the Account Name as shown below:

Resulted Data
Resulted Data

We hope that you find this blog helpful, if you still have queries, don’t hesitate to contact us at salesforce@greytrix.com.

About Us
Greytrix – a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.

Greytrix has some unique solutions for Cloud CRM such as Salesforce Sage integration for Sage X3Sage 100 and Sage 300 (Sage Accpac). We also offer best-in-class Cloud CRM Salesforce customization and development services along with services such as Salesforce Data MigrationIntegrated App developmentCustom App development and Technical Support to business partners and end users.
Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU™ integration for Sage ERP – Salesforce is a 5-star rated app listed on Salesforce AppExchange.

The GUMU™ Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.

For more information on our Salesforce products and services, contact us at salesforce@greytrix.com. We will be glad to assist you.

Related Posts