Salesforce | Call Apex class from Process Builder

|
| By Webner

Salesforce process builder is a tool to automate the processes using user interface itself. 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.

To call an Apex method, add the Call Apex action to your process and select an Apex class with an invocable method. It’s that easy.

Apex class example:

public class AutoConvertLeads {
@InvocableMethod
public static void Testmethod(Integer LeadIds) {
YOur code……………………
}
}

Now it’s time to create the flow using process builder. To accomplish this following steps are needed:

1.From Setup, enter Process Builder in the Quick Find box, click Process Builder, and then click New.
2.Name the process (say test process). The API name updates to test process when you tab out of the Name From Setup, enter Process Builder in the Quick Find box, click Process Builder, and then click New.
3.Click Save.
4.Click Add Object to associate your process with an object. For this example, we will choose a Lead object and bind the process to the event when the record is created or edited:
1
5.Click Save.

Add Criteria: It is time to define the criteria that must be met before the process can execute the associated actions. For this process, we want to check whether the Lead status has been closed and Open:

1.Click Add Criteria.
2.Name the criteria “Lead criteria”.
3.Leave Conditions are met selected to evaluate specified field values for the opportunity record:
2
4.Click save.

Add Actions to Execute when the Criteria are Met:

1.Under Immediate Actions, click Add Action.
2.Select Apex class in Action Type.
3.Put name in action name (say test action)
4.The classes with the invocable method are available in Spex class field. Select the desired class.
5.You can also send parameters to the method. For this click on Add row in set apex section.
6.Select field of apex method.
7.Set type of value. (You can select formula, Global constant, reference, and id)
8.Put value.
9.Click save:
3
Your process is defined and ready!

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *