Document Contexts

From 3B Knowledge
Jump to navigation Jump to search

A "context" refers to the object type from which we are creating instructions to pull data from. When creating a template, only a single "main"/ "core" context can be applied.

Intro

When creating Templates, you have the option to select a "Context Object" and a "Merge Object". These two selects will drive what fields and options you have access to.

Context Object

Context Object selector in template editor

The "Context Object" select is designed as a top-level contextual object selector. More often than not, it will drive the context of the entire document.

This is a list of all the objects (standard and custom) available in your instance of the Salesforce environment.

Depending on the version of the app you have installed, the list will include the object label and and a three character unique code (key prefix) will be displayed in brackets next to the object label.


The object label itself is determined dynamically - it is either the actual name of the object, say "Contact" or it could be the override/translated value, say "Person". This is where the three character unique code in the brackets after the object label comes useful in determining which object is actually behind the label displayed.


Some objects will be disabled for selection. Such objects will be displayed as greyed out. Here are some reasons why an object may not be available for selection:

  • Your system user does not have "Read" permission to the object
  • Your system user does not have access to the object which requires a license to see/query
  • The object is deprecated or hidden
  • The object is not queryable

Merge Object

Merge Object selector in template editor

The "Merge Object" selector is dependent on the Context Object selector. The options displayed in the selector are:

  • The first and top option is always going to be the same as the selected context object
  • The other options displayed are all child related objects (objects which have a lookup or master-detail relationship to the context object).

Child related object options add an additional string after the label and key prefix of the object - the API name of the relationship field that links the child related object to the context object.

Nested Contextual Objects

The system is designed so that you can have only one main context but then you can go as many child levels deep as you need - this is called "contexts nesting".

Contexts nesting allows you to extract data from child and parent objects by traversing through the object tree of your Salesforce instance.

Object Merge Field

The "Object Merge Field" is an extremely important part of providing contexts for data merging. We use the object merge field in order to pull records by the contextual record's ID.

So, if your template implements "Account" as the context object and you want to add a related child context of say "Contact", you can select the Merge Object as "Contact (003) - AccountId" which will add child Contact related object identified through the "AccountId" field. The system will get all contacts related to the contextual Account through the field "AccountId".


For nested contexts, the merge field is mapped based on the direct parent context:

Account (Core/Main Object)

L Contacts through AccountId => get contacts where the AccountId field is equal to the id of the parent Account context

L Cases through ContactId => get cases where the ContactId field is equal to the id of the parent Contact context (which in terms is retrieved by the AccountId field matching the id of the parent Account)

L Cases through AccountId => get cases where the AccountId field is equal to the id of the parent Account context

Current Context

"Current Context" refers to the the process of identifying what object is contextual to where the cursor is placed or where a merge tag or other tool is positioned.

Usually, the current context refers to the template core object. However, when child related objects or other context amending features are added to the template, the context may change.

Examples

Let's say you need to create a document that shows some account details and then lists each related contact under which we need to list each related case that the contact has raised.


To do this, you would start by selecting the Context Object as "Account" - this will become the main/core object of the template that we are creating. You can now add merge fields from the account object by using the merge field selector.

An example of multiple nested child contexts

Next, you can change the "Merge Object" to "Contact (003) - AccountId" - this will allow you to add a related child context of "Contact" that will extract contacts linked to the Account through the field "AccountId".

Finally, to get the cases linked to the child Contact, we would need to change the "Context Object" select to "Contact" and select the merge object "Case (500) - ContactId" - i.e. Cases linked to the contact through the ContactId merge field on the Case.