Skip to main content

Sync Customers Filtered by Account Group

You can filter your customer sync by a specific SAP Account Group when using EnosixCustSync.

info

Use the following link for help on creating Apex classes in Salesforce: Adding an Apex Class.

Use information from the valence.LinkContext if you wish to use the same Apex class with more than one Link and wish to vary the behavior of your filter based on which Link is currently running.

Example of account groups:

  • Sold-To = Account Group 0001
  • Ship-To (Goods Recipient) = Account Group 0002

Here is the code you will need for your Apex class to filter your link by Account Group:

LimitCustomersByAccountGroupCallable.apxc
global class LimitCustomersByAccountGroupCallable implements Callable {
global Object call(String action, Map<String, Object> args) {
if (action == ensxsync.EnosixAdapter.UPDATE_PARAMS_ACTION) {
Map<String, Object> searchContext = (Map<String, Object>) args.get(ensxsync.EnosixAdapter.SEARCH_CONTEXT_KEY);
Valence.LinkContext linkContext = (Valence.LinkContext) args.get(ensxsync.EnosixAdapter.LINK_CONTEXT_KEY);
applyAll(searchContext, 'ACCOUNT_GROUPS', new List<Map<String, String>>{
new Map<String, String> { 'KTOKD' => '0001' },
new Map<String, String> { 'KTOKD' => '0002' }
});
return searchContext;
}
return null;
}
@TestVisible
private void applyAll(Map<String, Object> searchContext, String key, Object values) {
if (searchContext.containsKey(key)) {
if (searchContext.get(key) instanceof Map<String, String>) {
((Map<String,String>)searchContext.get(key)).putAll((Map<String, String>)values);
}
if (searchContext.get(key) instanceof List<Map<String, String>>) {
((List<Map<String, String>>)searchContext.get(key)).addAll((List<Map<String, String>>)values);
}
} else {
searchContext.put(key, values);
}
}
}
Apex Unit Test Code
LimitCustomersByAccountGroupCallableTest.apxc
@IsTest
private class LimitCustomersByAccountGroupCallableTest {
private static LimitCustomersByAccountGroupCallable testInstance = new LimitCustomersByAccountGroupCallable();

@IsTest static void testCall() {
System.assertEquals(null, testInstance.call(null, null), 'Expect null return and no Exceptions with null inputs');
String originalTestValue = '42';
Object actual = testInstance.call(
ensxsync.EnosixAdapter.UPDATE_PARAMS_ACTION,
new Map<String, Object>{
ensxsync.EnosixAdapter.SEARCH_CONTEXT_KEY => new Map<String, Object>{
'SEARCHPARAMS' => new Map<String, String> { 'TEST_VALUE' => originalTestValue }
}
}
);
System.assertNotEquals(null, actual, 'Expect search context returned');
String actualTestValue = ((Map<String, String>)((Map<String, Object>)actual).get('SEARCHPARAMS')).get('TEST_VALUE');
System.assertEquals(originalTestValue, actualTestValue, 'Expect SEARCHPARAMS=>TEST_VALUE to be untouched');
}

@IsTest static void testCoverageForApplyAll() {
testInstance.applyAll(
new Map<String, Object>{},
'KEY',
null
);
testInstance.applyAll(
new Map<String, Object>{
'KEY' => new Map<String, String>{}
},
'KEY',
new Map<String, String>{}
);
testInstance.applyAll(
new Map<String, Object>{
'KEY' => new List<Map<String, String>>{}
},
'KEY',
new List<Map<String, String>>{}
);
System.assert(true, 'Expect completion without Exceptions');
}
}