Testing Strategies
TestHelper Methods
CallCore TX provides a callcoreio.TestHelper global class that lets you exercise your strategy implementations in Apex tests without needing to trigger a full timeline request or deploy the metadata registration record.
Each method accepts your strategy implementation and any required inputs, invokes the strategy against a live Context, and returns an Inspector — an object that exposes the results in a readable, assertion-friendly form.
| Method | Strategy | Returns |
|---|---|---|
buildCommunicationScope(impl, anchorRecordId) |
BuildCommunicationScopeForRecord |
CommunicationScopeForRecordInspector |
gatherPhoneNumbersFromRecords(impl, recordRefs) |
GatherPhoneNumbersFromRecords |
PhoneNumbersFromRecordsInspector |
tryGetUserForCallHandler(impl, subdomain, email, displayName, rawDisplayName, extensionNumber) |
GetUserForCallHandler |
GetUserForCallHandlerInspector |
restrictCallHandlers(impl) |
RestrictCallHandlers |
RestrictCallHandlersInspector |
restrictSources(impl) |
RestrictSources |
RestrictSourcesInspector |
Inspectors are test-only. Calling any Inspector method outside of a test context throws callcoreio.Exceptions.CallCoreTestOnlyException.
Inspector Reference
CommunicationScopeForRecordInspector
| Method / Property | Type | Description |
|---|---|---|
hasErrors |
Boolean |
True if any errors were added via context.addError(). |
getErrors() |
List<callcoreio.Error> |
The errors recorded during build(). |
getIdsInScope() |
Set<Id> |
All record IDs added to scope, across all SObject types. |
PhoneNumbersFromRecordsInspector
| Method | Returns | Description |
|---|---|---|
toResultsByRecord() |
List<callcoreio.PhoneNumbersFromRecord> |
One entry per record that had phone numbers added. Call .toPhoneNumberSet() on each entry to get the numbers. |
toResultsByPhoneNumberMap() |
Map<String, List<callcoreio.PhoneNumbersFromRecord>> |
Keyed by normalised phone number; useful for looking up which records match a given number. |
callcoreio.PhoneNumbersFromRecord exposes recordRef (callcoreio.RecordRef), displayName (String), and toPhoneNumberSet() (Set<String>).
GetUserForCallHandlerInspector
| Method | Returns | Description |
|---|---|---|
getUserId() |
Id |
The User ID recorded by context.found(), or null if notFound() was called or neither was called. |
RestrictCallHandlersInspector
| Method | Returns | Description |
|---|---|---|
getAllowedIdsOrNullForAll() |
Set<Id> |
The allowed handler User IDs, or null if allowAll() was called. |
isAllowAll() |
Boolean |
True if the strategy called allowAll() or called no write method. |
isAllowNone() |
Boolean |
True if the strategy called excludeAll() or passed an empty set to allowSet(). |
RestrictSourcesInspector
| Method | Returns | Description |
|---|---|---|
getAllowedIdsOrNullForAll() |
Set<Id> |
The allowed Source record IDs, or null if no write method was called (allow-all). |
isAllowAll() |
Boolean |
True if no write method was called. |
isAllowNone() |
Boolean |
True if excludeAll() was called or an empty set was passed to allowSet(). |
Examples
Testing BuildCommunicationScopeForRecord
@isTest
private class BuildProjectCommsScopeTests {
@isTest
static void scopeIncludesProjectAndAccount() {
Account acc = new Account(Name = 'Test Account');
insert acc;
Project__c proj = new Project__c(Name = 'Test Project', Account__c = acc.Id);
insert proj;
BuildProjectCommsScope strategy = new BuildProjectCommsScope();
callcoreio.TestHelper.CommunicationScopeForRecordInspector inspector =
callcoreio.TestHelper.buildCommunicationScope(strategy, proj.Id);
Set<Id> scope = inspector.getIdsInScope();
System.assert(scope.contains(proj.Id), 'Project should be in scope');
System.assert(scope.contains(acc.Id), 'Account should be in scope');
System.assertEquals(false, inspector.hasErrors, 'Should not have errors');
}
}
Testing GatherPhoneNumbersFromRecords
@isTest
private class GatherPhoneNumbersFromSuppliersTests {
@isTest
static void gathersAllThreePhoneFields() {
Supplier__c s = new Supplier__c(
Name = 'Acme',
MainPhone__c = '+441234567890',
EmergencyPhone__c = '+449876543210',
Mobile__c = null
);
insert s;
callcoreio.RecordRefSet refs = callcoreio.RecordRefSet.of(s.Id);
GatherPhoneNumbersFromSuppliers strategy = new GatherPhoneNumbersFromSuppliers();
callcoreio.TestHelper.PhoneNumbersFromRecordsInspector inspector =
callcoreio.TestHelper.gatherPhoneNumbersFromRecords(strategy, refs);
List<callcoreio.PhoneNumbersFromRecord> results = inspector.toResultsByRecord();
System.assertEquals(1, results.size(), 'Should have one record');
System.assertEquals(2, results[0].toPhoneNumberSet().size(), 'Should have two phone numbers (null ignored)');
}
}
Testing GetUserForCallHandler
@isTest
private class GetUserForCallHandlerByExtensionTests {
@isTest
static void findsUserByExtension() {
User u = [SELECT Id FROM User WHERE IsActive = true LIMIT 1];
u.PhoneExtension__c = '1234';
update u;
GetUserForCallHandlerByExtension strategy = new GetUserForCallHandlerByExtension();
callcoreio.TestHelper.GetUserForCallHandlerInspector inspector =
callcoreio.TestHelper.tryGetUserForCallHandler(
strategy,
'myworkspace', // subdomain
null, // email
null, // displayName
null, // rawDisplayName
1234 // extensionNumber
);
System.assertEquals(u.Id, inspector.getUserId(), 'Should match user by extension');
}
}
Testing RestrictCallHandlers
@isTest
private class RestrictHandlersToRoleHierarchyTests {
@isTest
static void allowsAllWhenUserHasViewAllPermission() {
PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'CallCore_TX_ViewAllCalls' LIMIT 1];
insert new PermissionSetAssignment(AssigneeId = UserInfo.getUserId(), PermissionSetId = ps.Id);
RestrictHandlersToRoleHierarchy strategy = new RestrictHandlersToRoleHierarchy();
callcoreio.TestHelper.RestrictCallHandlersInspector inspector =
callcoreio.TestHelper.restrictCallHandlers(strategy);
System.assertEquals(true, inspector.isAllowAll(), 'ViewAllCalls user should see all handlers');
}
}
Testing RestrictSources
@isTest
private class RestrictSourcesByProfileTests {
@isTest
static void allowsAllWhenNoRulesConfigured() {
RestrictSourcesByProfile strategy = new RestrictSourcesByProfile();
callcoreio.TestHelper.RestrictSourcesInspector inspector =
callcoreio.TestHelper.restrictSources(strategy);
System.assertEquals(true, inspector.isAllowAll(), 'No rules should mean allow all');
}
}
Notes
TestHelpermethods invoke your strategy directly — they do not go throughStrategyFactoryor read anyExtensibilityStrategy__mdtrecords. You do not need to create metadata records in your test class.- Because strategies run in the test context, sharing rules, governor limits, and DML all apply normally. Insert test data with
@testSetupor within the test method as usual. - The
TestHelperclass is annotated@isTestand is not included in production deployments. You cannot call it from production code.