Get to Know Context Service
Learning Objectives
After completing this unit, you’ll be able to:
- Define data abstraction.
- Explain Context Service and its purpose.
- Describe the benefits of Context Service.
- Outline the capabilities of Context Service.
Data Abstraction
When you're developing a software product, your aim is to simplify data structures and improve usability for end users. Data abstraction achieves this objective by hiding the complexities and irrelevant details from end users. This approach makes data retrieval faster and the overall system more efficient. You can design a system where the user accesses only the necessary data without being overwhelmed by how the data is stored and accessed in the system.
Consider this example: A typical smartphone user doesn’t know how the phone makes calls, accesses the internet, or stores their photos and videos. They simply use the phone’s user interface (UI) to perform these functions and don’t worry about the technical intricacies. Context Service works similarly for data access. Here’s how.
Context Service at a Glance
Context Service is an advanced solution designed to simplify data management and integration for businesses. It hides or abstracts the underlying data sources from applications, so developers can work with a unified and logical data model. This abstraction helps them to create seamless and user-friendly applications, without getting bogged down by the complexities of different data sources. Applications interact with data logically rather than directly accessing each source. Meanwhile, admins handle the behind-the-scenes connections to actual data sources, ensuring everything runs smoothly.
By standardizing data interactions, Context Service reduces the time and effort it takes to interact with multiple data sources. This standardization not only simplifies workflows, but also improves data accuracy and consistency across the organization. As a result, businesses make more informed decisions, faster, without worrying about data silos or inconsistencies.
Context Service supports advanced features such as context mapping, memory optimization, and integration with other Salesforce products such as Flow and Business Rules Engine. These features empower businesses to customize their data interactions to meet specific needs, ensuring they adapt quickly to changing demands.
Why Use Context Service?
Consider an application that interacts with various data sources, including customer information, product inventory, and order histories to get the data. In the past, developers had to write complex code for each database to integrate these data sources, which was time-consuming and error-prone.
Context Service acts as an intermediary between applications and the database. An application also includes multiple processes and steps. Every time a process executes, each step communicates with the database to fetch data. These frequent trips to the database increase latency and reduce system performance.
Study this process flow to learn how you can use Context Service to fetch and serve data between application process steps and database.
When steps in an application process need data, they simply send a request to Context Service. Context Service then retrieves the data from the appropriate database, and sends the data back to the steps. As a result, developers can focus their attention on building the application’s features, rather than spending time on data integration.
Context Service can also update data in the database. For example, when an application updates the inventory after a sale, it writes the data back to Context Service. Then, Context Service ensures that the update is processed correctly and written to the appropriate database. This seamless interaction not only saves the developer’s time but also ensures data consistency and reliability across the system.
Thanks to Context Service, developers develop and deploy their applications faster with greater confidence, knowing that the underlying data management is handled efficiently and effectively. This leads to a more robust application and a more satisfied customer base.
Benefits of Context Service
Context Service offers several key benefits that make it an invaluable tool for businesses. Click each benefit to learn more.
In short, these benefits together ensure that Context Service meets the diverse and evolving needs of your users.
Context Service Capabilities
Context Service provides several unique capabilities that help you optimize data processing. Time to learn about these capabilities in detail.
Context Definition Designer
A context definition is a composite structure that contains a set of multiple building blocks, such as nodes, attributes, and mappings. More on context definition in the next unit. Context Service provides a visual designer to create these context definitions, which you use to abstract data for your digital processes.
Here’s the Create Context Definition window where you can add the context definition details.
You can create a new context definition, or extend a prebuilt definition shipped by any Industry Cloud. You can also map a real data source to the definition.
APIs to Hydrate and Access Context
Context Service provides Connect APEX APIs to build a context in-memory, perform read or write operations on data, and persist data back to the Salesforce database.
Here’s a high-level process flow showing how Context Service queries and persists data.
When an application needs data, it sends a request to Context Service using context APIs. Next, Context Service builds an in-memory context instance. It then fetches the data from the database and stores the data in the instance. Industry Clouds use the APIs to fetch and interact with the transactional data in Context Service to serve their digital processes.
A context definition consists of metadata that defines the structure of the context. Whereas, a context instance is a run-time instantiation of a context definition and contains the actual data. The instance resides in temporary transient data stores for faster data access. Here’s a list of the APEX APIs that you can use in context service to perform different data operations.
-
Build: Use these APIs to load data into the context from a data source, and search or delete a context.
-
buildContext: Create a context instance at run time.
-
getContext: Retrieve context details.
-
deleteContext: Delete a context instance.
-
buildContext: Create a context instance at run time.
-
Query: Use these APIs to query data in the context.
-
queryContextRecordsAndChildren: Retrieve records and their child records from a context instance at run time.
-
queryTags: Retrieve tag values from a context instance.
-
queryContextRecordsAndChildren: Retrieve records and their child records from a context instance at run time.
-
Update: Use these APIs to update or add data in the context.
-
updateContextAttributes: Update data in a context instance.
-
addRecordToContext: Add new data to a context instance.
-
updateContextAttributes: Update data in a context instance.
-
Persist: Use this API to save context data to the data source.
-
persistContext: Write the current context data to a database.
-
persistContext: Write the current context data to a database.
Business Object Transformation
Context Service APIs can transform one business object into another. For example, you can transform a quote into an order, or an opportunity into a contract. Context Service can also write these newly transformed objects to a database.
Here’s a high-level process flow showing how Context Service transforms and persists data.
Context Service hydrates or fetches data from the source object, transforms it, and persists the data to the target object.
What’s Next
In this unit, you learned about data abstraction and got an overview of Context Service, including its benefits and capabilities. In the next unit, explore the various Context Service components, and design-time and run-time processes.