Tuesday, March 9, 2021

Apex Remote Call from OmniScript and Card

Apex Remote Call from Vlocity OmniScript and Vlocity Card

Vlocity Provides power tools like Dataraptor to Query, Insert, and Update the Records, however, if we would need to perform any business logic check or any complex logic we need to call the apex class.

Apex Remote call from Vlocity OmniScript -

Requirement -

As a part of Product Service, Agent will capture the customer details and purchased product details. The ticket will be created in the background and will be assigned to a service queue-based problem statement.

Here, we are trying to create an Omniscript using that agent can log tickets as a part of the product service setup. 

Basic Setup -

As a part of the basic setup, I have created a few input text boxes to take inputs after that, I have placed them on Remote Action to call the apex methods -
















Remote Action Setup-

In order to call the Apex Remote functions, we would need to drag the Remote Action from the Available Components.

Remote Action is available on the left side tab views. Please refer to the below snapshot -

As a part of Remote Action Configuration, we need to mention the Element Name, Remote Class, Remote Method. 

Remote Class: <Mention the Apex Class Name>
Remote Method: <Metion the Method Name>



Parameters Configuration:

As a part of Remote Action, we can pass values to controller in the below two ways. I will mention more details on these in the "How to Debug OmniScript Remote Issue".
  • All the OmniScript JSON nodes will be passed to method. We can use Input Map in order to access those with Step Names, we need to JSON parsing in that case to read the values
  • If we would need to read few input fields/ JSON nodes, we can follow below approach - 

Apex Class:   Sharing the Sample code below

In the VlocityOpenInterface interface we have method call invokeMethod. 
We would need to write our custom logic here
  • First String Parameter will hold the method name, the same value that we have mentioned while Remote Action configuration
  • Input Map will return us all the JSON nodes from OmniScript and Extra Payload details from Configurations
  • Output Map will hold the return data from the Custom Method. After performing custom Logic, 
  • if we want to pass anything to controller, we need to use the option also

/* * Class: CreateContactController * Descriptions: In order to call the Apex Class from the OmniScript * and Vlocity Card, we need to implement vlocity_cmt.VlocityOpenInterface interface * */ global class CreateContactController implements vlocity_cmt.VlocityOpenInterface { /* * Method Name: invokeMethod * Return Type: Boolean * Input Parameters: String, Map<String,Object>, Map<String,Object>, Map<String,Object> * Descriptions: In the VlocityOpenInterface interface we have method call invokeMethod. * We would need to write our custom logic here * Input Map will return us all the JSON nodes from OmniScript and Extra Payload details from Configurations * Output Map will hold the return data from the Custom Method. After performing custom Logic, * if we want to pass anything to controller, we need to use the output * */ global Boolean invokeMethod(String methodName, Map<String,Object> input, Map<String,Object> output, Map<String,Object> option){ System.debug('***input**** ' + input); //MethodName Will be same as the value that we have mentioned while calling the Remote Action if(methodName == 'CreateContact'){ //Creating Instance of Contact Contact contactToCreate = new Contact(); contactToCreate.FirstName = getFieldValue(input,'fName'); contactToCreate.LastName = getFieldValue(input,'lName'); contactToCreate.Email = getFieldValue(input,'email'); contactToCreate.Phone = getFieldValue(input,'phone'); //Checking the Profile Accessiblity to Create the Contact SObjectAccessDecision decision = Security.stripInaccessible( AccessType.CREATABLE, new List<Contact>{contactToCreate}); if(!decision.getRecords().isEmpty()){ insert decision.getRecords(); output.put('contactId',decision.getRecords()[0].Id); } } return true; } /* * Method Name: getFieldValue * Parameter: Map<String,Object>, String * Return Type: String * Description: It will return the value from Map after reading the value */ private String getFieldValue(Map<String,Object> input, String key){ if(input.containsKey(key)){ return String.valueOf(input.get(key)); } return ''; } }

How to Read Returned value from Apex Method:

In order to read the values, we can refer %NodeName%. While creating of the outmap, the node name we will be mentioning here, we need to mention the same 


Configuration from the OS


 

Output











Thursday, March 4, 2021

Daily Blog On Vlocity

My Journey In Vlocity -

I have worked for around 3.5 years in the Vlocity Insurance and Telecom Package. Mostly, I have worked on the OmniScript, Vlocity Card & Layout, Vlocity Template, Action, Integration Procedures, Vlocity Apis.

I have written Custom Vlocity templates in Angular and using LWC as well. Here, I would like to share my experiences


Why should we choose Vlocity -

Now, Vlocity is part of Salesforce Industries. To answer this question, we should consider two-part-

  • How will it help business? Vlocity has been developed on top of Salesforce. When we say Vlocity Insurance Package or Vlocity Telecom package, Vlocity has its core modules, on top of it, Vlocity has added a different flavor for different business lines to match the different business lines. Also, Vlocity provides Process Library provides a preloaded business process that helps to do a jump start in terms of implementation. Also, it provides rich powerful tools to implement a custom solution very quickly.

  • How will it help the technical team? With the Powerful Vlocity tools, we can create custom UI with a point n click approach.

What will I cover in this blog -

Here I would like to share my experience to build a custom solution in Vlocity, like how we can call apex call from Vlocity OmniScript and Card or how we can build custom template in vlocity.