Sample Implementation to Override the 255-Character Limitation

The Digital Commerce APIs use the vlocity_cmtAPIParamsc field in the vlocity_cmtVlocityAPIMetaDatac sObject to configure request response fields, batch size, and other options. This field is also used to identify certain settings of the API while processing batch jobs or while processing API requests at run time.

However, the vlocity_cmt_APIParams__c field is by default limited to 255 characters. In some scenarios, this can be insufficient. For example, consider the following JSON request for a batch job:

1{"batchSize":20,"scopeAll":true, "productFields" : ["vlocity_cmt__IsActive__c"]}

In this example, if you specify multiple fields in productFields, the vlocity_cmt_APIParams__c field might exceed the 255 character limitation. In such cases, to increase the number of characters this field can contain, you can override the default character limitation. To do this, you can create an Apex class along with an interface implementation. For example, create an implementation similar to the following sample.

Sample Implementation Name

DCAPIParamsImplementation

Sample Implementation Method

fetchAPIParamsOverride

Input

KeyTypeDescription
apiNameStringDefines the name of the API from vlocity_cmtVlocityAPIMetaDatac.vlocity_cmtAPINamec
paramsStringDefines the parameters of the given API name. This represents vlocity_cmtVlocityAPIMetaDatac.vlocity_cmtVlocityAPIMetaDatac

Output

KeyTypeDescription
resultStringUpdates the API parameters for the given API name.

Sample Implementation

1/*
2 * We can override this default implementation by defining the following interface
3 * INTERFACE : DCAPIParamsInterface
4 */
5global class DCAPIParamsImplementation implements vlocity_cmt.VlocityOpenInterface {
6	public static Map < String, String > overiddenParamMap = new Map < String, String > {};
7	static {
8		//Field should have their own string here for getoffers api
9		overiddenParamMap.put('GetOffers', '{"batchSize":20,"productFields" : ["vlocity_cmt__IsActive__c"]}');
10		//Field should have their own string here for getofferdetails api
11		overiddenParamMap.put('GetOfferDetails', '{"batchSize":20}');
12		//Field should have their own string here for getrelatedofferdetails api
13		overiddenParamMap.put('GetRelatedOffers', '{"batchSize":20, "productFields" : ["vlocity_cmt__IsActive__c"]}');
14	}
15	global DCAPIParamsImplementation() {}
16
17	global static Boolean invokeMethod(String methodName, Map < String, Object > inputs, Map < String, Object > outputs, Map < String, Object > options) {
18		if (methodName == 'fetchAPIParamsOverride') {
19			return fetchAPIParamsOverride(inputs, outputs, options);
20		}
21		return false;
22	}
23
24	/*
25	Inputs :
26	    1) key : apiName, type : String
27	    2) key : params, type : String
28	Outputs :
29	    1) key : result, type : String
30	*/
31	public static Boolean fetchAPIParamsOverride(Map < String, Object > inputs, Map < String, Object > outputs, Map < String, Object > options) {
32		String apiName = (String) inputs.get('apiName');
33		String overiddenParam = overiddenParamMap.get(apiName) == null ? ((String) inputs.get('params')) : overiddenParamMap.get(apiName);
34		outputs.put('result', overiddenParam);
35		return true;
36	}
37}