This blog post will go over how to use a Screen Flow to call an Apex class using a straightforward example. The Screen Flow generated in this example has three variables that we have created. Initially, recordId is configured to be available for both input and output.
1. RecordId Variable
The second variable that we have created is the Account to store Account Data.
2. Account Variable
The third variable that we have created is Name. That stores the return value of the Apex class called in the flow.
3. 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:
4. 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.
5. Check Return Value
After that, we create a screen to show the name of that Account, if the condition is satisfied.
6. Edit Screen
Likewise, the whole flow can be built as shown in the image below:
7. ScreenFlow
Likewise, after you have completed built the flow you can create a Button Invoke Method to call the flow:
8. Account Screen with Invoke Method Button
After execution of the flow, we get a Screen which shows the Account Name as shown below:
9. 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 X3, Sage 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 Migration, Integrated App development, Custom App development and Technical Support 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