Tuesday, 28 July 2015

Lightning Process Builder (Calling apex from Process builder)

The Process Builder is a workflow tool that helps you easily automate your business processes by providing a powerful and user-friendly graphical representation of your process as you build it. The Process Builder’s simple and powerful design allows you to:
§  Create your processes using a convenient layout with point-and-click efficiency.
§  Create your whole process in one place rather than using multiple workflow rules.
§  Create processes by collaborating with different teams in your business.
§  Stop using Apex code to automate simple tasks

I am trying to explain how we can invoke apex through process builder.
To invoke apex from process builder ,we have to use annotations “invocableMethod” for method and “invocableVariable” for variable.
We can invoke the apex class  which includes the invocablemethod only from the process builder.
Navigation for Process Builder:

Setup- >Build -> Workflow & Approvals –> Process Builder

Creating Process:

Elements of Process:

Adding Salesforce object:

Adding Conditions:

Apex Invocation: (Apex class which contains Invocable methods only appear in the Apex Action of process builder)

Here apex variables are invocable variable which are useful to hold the values of record like lead id ,firstname,LastName as shown above. By using the apex invokable variable we can process  the business logic in invokable method as shown below.
Example Class:
globalclass InvocableMethodcls {
              //An invocable variable used as input or output variables in the process builder
              globalclass ActionRequest {
       public ID leadId;
       public String phone;
       public String email;
       publicLead leadObj;
       public String firstName;
       public String lastName;
       //This invocable method is used for processing the business by taking the input from process builder
       @InvocableMethod(label='Invoke Business Logic')
       globalstaticvoid invokeService(List<ActionRequest> requests){       
              for(ActionRequest requestObj:requests){        
                     //Accessing the values from process builder when record is inserted
              //We can write our own business logic herer.

Activating The process:

Lead Creation:

Output(Debug Log):


No comments:

Post a Comment

Refresh Interval of different types of Sandboxes

Hi, We have different refresh intervals for different sandboxes as shown below. Sandbox Type Refresh Interval ...