Calling apex class from Lightning process builder

August 29th, 2017 . 2 minutes read
Blog featured image

Do you want to know how to call an apex class in Lightning Process Builder? Let’s discuss all you want to know shortly here in this article.

Overview of lightning process builder:

The Process Builder is a new workflow tool from spring release 15 that promises you to easily automate your business processes by providing a powerful and user-friendly visual representation of your process as you build it. The Process Builder’s simple and powerful design which not only creates, updates records, send emails, call a Flow, Post to Chatter and Submit for approval but also calls apex class in order to achieve requirements which can’t be done by any of the above.

To answer this question @InvocableMethod comes into play. A process builder can call only apex classes which implemented @InvocableMethod annotation for a static method in it.

Only one @InvocableMethod is allowed for one class.

At the time of writing this post, the current release is summer 15, until now the method accepts only one argument.

In order to pass more than one argument from process builder, you want to create a class with @InvocableVariable this allows you to pass multiple variables from process builder.


Delete the related contacts of an account when a checkbox is checked in an account.


Create a process that executes when that checkbox value is true which calls an apex class to delete the related contacts.

* Don’t forget to Activate the process after you have created it.

The process builder will look like this

Create a class named as DeleteRelatedContacts and copy paste the below code.


conclusion :

Here we can select source object, criteria/event to initiate the process as well and the action to be taken on the occurrence of the event.
In actions section of process builder, we can execute apex method as well. This is the main advantage of process builder as we cannot execute the apex class using flows or workflows.

This is the main advantage of process builder as we cannot execute the apex class using flows or workflows.

Do you want to add something in this article? share your views in the comment section.


Author: Jignesh