You are here:
Create a Class-Based Interaction Launcher
Create a class-based interaction launcher, which uses an Apex class to get a search request and search response.
-
Create a global Apex class that implements, for example:
-
vlocity_ins.VlocityOpenInterface - OR
-
vlocity_ins.VlocityOpenInterface2
global with sharing class GetMockupSearchRequestResults implements vlocity_ins.VlocityOpenInterface2 -
-
Include two methods:
-
getSearchRequest -
getSearchResults
global Object invokeMethod(String methodName, Map < String, Object > inputs, Map < String, Object > output, Map < String, Object > options { Boolean success = true; if (methodName == 'getSearchRequest') { success = getSearchRequest(inputs, output, options); } if (methodName == 'getSearchResults') { success = getSearchResults(inputs, output, options); } return success; } -
-
Then construct the
vlocity_ins.LookupRequestinterface:vlocity_ins.LookupRequest request = (vlocity_ins.LookupRequest) inputs.get('lookupRequest'); List<Map<String, Object>> previousSearchResults = request.previousSearchResults; Map<String, Object> additionalData = request.additionalData; List<String> searchFieldList = request.searchFieldList; searchFieldList.add('FirstName'); searchFieldList.add('LastName'); Map<String, Map<String, String>>labelTypeMap = request.searchFieldsLabelTypeMap; Map<String, String> newType1 = new Map<String, String> (); newType1.put('label','First Name'); newType1.put('datatype','text'); labelTypeMap.put('FirstName',newType1); Map<String, String> newType2 = new Map<String, String> (); newType2.put('label','Last Name'); newType2.put('datatype','text'); labelTypeMap.put('LastName',newType2); Map<String, Object> valueMap = request.searchValueMap; valueMap.put('FirstName',null); valueMap.put('LastName',null); System.debug(' LookupRequest is '+request); output.put('lookupRequest', request); -
Construct the
vlocity_ins.LookupResultinterface (see example code below). - Create a Vlocity Interaction Launcher record.
- Pick Class Based for the entry field Record Type:
- Complete any pending information.
-
Insert the class created from step 1 (
GetMockupSearchRequestResults) into the entry field Invoke Class Name. -
Launch the class-based interaction.
vlocity_ins.LookupResult Interface Example Code:
List < String > contextIds = (List < String > ) inputs.get('contextIds'); String parentId = (String) inputs.get('parentId'); vlocity_ins.LookupRequest request = (vlocity_ins.LookupRequest) inputs.get('lookupRequest'); String lastRecordId = request.lastRecordId; // R15 pagination support Map < String, Object > resultInfo = (Map < String, Object > ) inputs.get('resultInfo'); Integer pageSize = 0; // R15 pagination support Integer numRecords = 30; // R15 pagination support // R15 pagination support // get ClassBasedResultsPageSize from customSetting // R15 pagination support vlocity_ins__InteractionLauncherConfiguration__c myCS = vlocity_ins__InteractionLauncherConfiguration__c.getInstance('ClassBasedResultsPageSize'); if ((myCS != null) && (myCS.vlocity_ins__IsFeatureOn__c)) { pageSize = String.isNotBlank(myCS.vlocity_ins__DisplayMessage__c) ? Integer.valueOf(myCS.vlocity_ins__DisplayMessage__c) : 10; } Boolean hasMore = false; // End R15 pagination support List < String > resultFieldList = new List < String > (); resultFieldList.add('RelatedParty'); resultFieldList.add('Role'); List < String > verificationFieldList = new List < String > (); verificationFieldList.add('PartyName'); verificationFieldList.add('Address'); List < String > optionalVerificationFieldList = new List < String > (); optionalVerificationFieldList.add('Role'); optionalVerificationFieldList.add('RelatedParty'); Map < String, Map < String, String >> resultFieldsLabelTypeMap = new Map < String, Map < String, String >> (); Map < String, String > newType1 = new Map < String, String > (); newType1.put('label', 'Related Party'); newType1.put('datatype', 'text'); resultFieldsLabelTypeMap.put('RelatedParty', newType1); Map < String, String > newType2 = new Map < String, String > (); newType2.put('label', 'Role'); newType2.put('datatype', 'text'); resultFieldsLabelTypeMap.put('Role', newType2); Map < String, String > newType3 = new Map < String, String > (); newType3.put('label', 'Name'); newType3.put('datatype', 'text'); resultFieldsLabelTypeMap.put('PartyName', newType3); Map < String, String > newType4 = new Map < String, String > (); newType4.put('label', 'Address'); newType4.put('datatype', 'text'); resultFieldsLabelTypeMap.put('Address', newType4); Map < String, Object > verificationResult = new Map < String, Object > (); String uniqueRequestName = (String) resultInfo.get('uniqueRequestName'); String drBundleName = (String) resultInfo.get('drBundleName'); String interactionObjName = (String) resultInfo.get('interactionObjName'); List < vlocity_ins.LookupResult > results = new List < vlocity_ins.LookupResult > (); if ((contextIds != null) && (contextIds.size() == 1) { Map < String, Object > resultValueMap = new Map < String, Object > (); resultValueMap.put('RelatedParty', 'John Smith'); resultValueMap.put('Role', 'Carrier'); resultValueMap.put('PartyName', 'John Smith'); resultValueMap.put('Address', '50 Fremont, San Francisco, CA'); String recordId = 'ExternalId'; vlocity_ins.LookupResult result = new vlocity_ins.LookupResul(resultFieldsLabelTypeMap, resultFieldList, resultValueMap, recordId, uniqueRequestName, request, verificationResult, verificationFieldList, drBundleName, interactionObjName); result.setOptionalVerificationFieldList(optionalVerificationFieldList); // R15 optional verification fields support results.add(result); } // R15 pagination support else { for (Integer k = 0; k < numRecords; k++) { Map < String, Object > resultValueMap = new Map < String, Object > (); resultValueMap.put('RelatedParty', 'John Smith' + String.valueOf(k)); resultValueMap.put('Role', 'Carrier'); resultValueMap.put('PartyName', 'John Smith' + String.valueOf(k)); resultValueMap.put('Address', '50 Fremont, San Francisco, CA'); String recordId = 'ExternalId' + String.valueOf(k); vlocity_ins.LookupResult result = new vlocity_ins.LookupResult(resultFieldsLabelTypeMap, resultFieldList, resultValueMap, recordId, uniqueRequestName, request, verificationResult, verificationFieldList, drBundleName, interactionObjName); result.setOptionalVerificationFieldList(optionalVerificationFieldList); results.add(result); } } if ((pageSize > 0) && (results.size() > pageSize)) { List < vlocity_ins.LookupResult > resultSubSet = new List < vlocity_ins.LookupResult > (); // results.sort(); Integer startIndex = 0; if (String.isNotBlank(lastRecordId)) { for (Integer i = 0; i < results.size(); i++) { if (results[i].recordId == lastRecordId) { startIndex = i + 1; } } } Integer j = 0; for (j = startIndex; (j < results.size()) && (j < startIndex + pageSize); j++) { resultSubset.add(results[j]); } if (j < results.size()) { hasMore = true; } output.put('lookupResults', resultSubset); if (hasMore) { output.put('hasMore', hasMore); } // End R15 pagination support } else { // Logger.db('GetExternalSearchRequestResults // LookupResult is // '+JSON.serializePretty(results)); output.put('lookupResults', results); }


