- 03 Jul 2024
- 2 Minutes to read
- Print
- PDF
Dot-walking
- Updated on 03 Jul 2024
- 2 Minutes to read
- Print
- PDF
Dot-walking refers to the method of utilizing dot notation to traverse the relationships between items. In Apex's data model, relationships define how objects are interconnected. Dot Walking is the process of accessing fields on related objects by linking the relationships and their associated fields using dots (.).
Use Case | Solution |
Let's say we have two custom objects in the ACME's ITSM application: Employee: Contains information about employees, including their name and department. Department: Stores details about departments, such as department name and location.
Now, suppose we want to retrieve the location of the department that an employee belongs to using dot walking. | Here's how we would do it in Apex: // Assuming 'emp' is an instance of the Employee object // We want to retrieve the location of the department the employee belongs to In this example:
By using dot walking (Department__r.Location__c), we can directly access the location of the department associated with the employee without needing to perform additional queries or lookups. This makes the code concise and efficient. |
Key Benefits of Dot-walking
Figure: Key Benefits of Dot-walking
How to use Dot-walking as an Application Designer
Use Case | Solution |
Sam the Application Designer wants to select the fields of the parent table & the related tables based on dot-walking concept, as described in the above section. | Sam can define the conditions either on the fields of the transaction table or on the related tables using the dot-walking concept as shown in the below screenshot. |
Figure: Dot-walking notation
By entering Workgroup . Primary Owner . Employee Id in the Field section, Sam can fetch the Employee Id of the Primary Owner of that Workgroup without having to access multiple tables.
Dot-walking Within Same Table
Let us consider the below transaction table:
SR_Master | |||
---|---|---|---|
SR ID | Caller ID | Symptom | Status |
1 | 1 | Need new laptop. | Closed |
2 | 2 | Need to install new software. | Open |
3 | 3 | Need to upgrade software. | Open |
Scenario: Get “Symptom” of the SR
Dot-walking: SR_Master . Symptom
Output:
Symptom |
---|
Need new laptop. |
Need to install new software. |
Need to upgrade software. |
Dot-walking from Main Table To another Table
Let us consider the below transaction tables:
SR_Master | ||||
---|---|---|---|---|
SR ID | Caller ID | Symptom | Status | Workgroup |
1 | 1 | Need new laptop. | Closed | 1 |
2 | 2 | Need to install new software. | Open | 2 |
3 | 3 | Need to upgrade software. | Open | 3 |
Workgroup_Master | ||
---|---|---|
Workgroup ID | Wokrgroup Name | Workgroup Owner |
1 | Workgroup 1 | 3 |
2 | Workgroup 2 | 1 |
3 | Workgroup 3 | 3 |
User Master | |||||
---|---|---|---|---|---|
User ID | User Name | Email id | Location | User Type | Department |
1 | David | david@acme.com | Pune | VIP | 2 |
2 | Frank | frank@acme.com | Bangalore | Normal | 3 |
3 | Mike | mike@acme.com | Delhi | Normal | 1 |
Scenario: Get “Workgroup Owner” of the SR
Dot-walking: SR_Master . Workgroup . Workgroup_Owner
By using the Dot-walking notation (.), we can access the Workgroup_Owner by traversing from one table to another table without having to select from multiple fields. In this scenario the Workgroup Owner details are fetched by traversing from the SR_Master Table to the Workgroup_Master Table automatically.