LinkContext
This is a class that is full of information that might be useful to your Adapter or Filter while it is executing. It is an example of the Context Object pattern.
LinkContext has information about the Link that is currently running. This is a key object that allows custom extensions to be as dynamic as possible, reacting to run-time information for the currently-executing Link and operating under that context.
For example, you can use LinkContext to know which table you should be querying from an external system, or which fields to get from that table. A Filter can use LinkContext to see what mappings are active and if any of them have had configurations defined for this Filter.
Because LinkContext is tightly coupled and intrinsic to a running Link, you’ll find it passed as a parameter to almost every interface method so you always have it handy.
Properties
Data Type |
Class Property |
Description |
---|---|---|
String |
linkName |
The API name of the Link that is running. Comes from the DeveloperName cMDT record for the Link. |
String |
linkSourceName |
The API table name of the source Table, if one has been defined. |
String |
linkSourceLabel |
The user-friendly label of the source Table, if one has been defined. |
String |
linkSourceTableDetails |
Additional details about the source table that the source Adapter wanted to store. |
String |
linkTargetName |
The API table name of the target Table, if one has been defined. |
String |
linkTargetLabel |
The user-friendly label of the target Table, if one has been defined. |
String |
linkTargetTableDetails |
Additional details about the target table that the target Adapter wanted to store. |
Boolean |
testingMode |
True if this Link is running in Test Mode. No TargetAdapter should write to its backing system in Test Mode. |
Boolean |
isReplay |
True if this Link run is a replay of serialized failed records. |
String |
sourceAdapterNamespace |
The namespace of the Adapter that is being used as the source Adapter. |
String |
sourceAdapterClassName |
The class name of the Adapter that is being used as the source Adapter. |
String |
targetAdapterNamespace |
The namespace of the Adapter that is being used as the target Adapter. |
String |
targetAdapterClassName |
The class name of the Adapter that is being used as the target Adapter. |
String |
recordSnapshotLoggingLevel |
The user’s selected level of logging. Picklist with possible values: All,Errors/Warnings,Errors Only,None |
Integer |
batchSizeLimit |
The maximum number of records that can be processed in each batch for this Link. |
DateTime |
lastSuccessfulSync |
The timestamp of the last time this Link successfully synced, or null if it has never successfully synced before. |
String |
lastSuccessfulCursor |
A value you stored, like a bookmark, during the last time this Link successfully synced, or null if it has never successfully synced before. |
Datetime |
now |
The timestamp that will be saved to the Sync Event as the retrieval timestamp. We recommend SourceAdapters fetch records with modification timestamps after lastSuccessfulSync and before now. |
Map<String, Mapping> |
mappings |
All active mappings for this Link. Inactive mappings will not be in this collection. |
List<Field Path> |
suggestedQueryFields |
A filtered list of what Valence thinks you should query for if you are a source Adapter working with this context. |
Test Coverage
Because LinkContext is so intrinsic to all facets of working with Valence, you will use an instance of one in just about every test method you write. Luckily, they’re trivially simple to set up and work with. Create one and set any properties you’ll need in your test.
// set up a new, empty instance
valence.LinkContext context = new valence.LinkContext();
// set properties that you need, for example testing a source Adapter
context.linkSourceName = 'SomeSourceTable';
context.batchSizeLimit = 200;
Test.startTest();
MyAdapter adapter = new MyAdapter();
valence.FetchStrategy strategy = adapter.planFetch(context);
Test.stopTest();