Dot-walking
  • 03 Jul 2024
  • 2 Minutes to read
  • PDF

Dot-walking

  • PDF

Article summary

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.

  • These two objects are related as follows:
  • Each employee is associated with a department through a lookup relationship.
  • Each department can have multiple employees.

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

String departmentLocation = emp.Department__r.Location__c;

In this example:

  • emp is an instance of the Employee object.
  • Department__r refers to the lookup relationship between Employee and Department.
  • Location__c is a field on the Department object containing the location information.

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 IDCaller IDSymptomStatus
11Need new laptop.Closed
22Need to install new software.Open
33Need 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 IDCaller IDSymptomStatusWorkgroup
11Need new laptop.Closed1
22Need to install new software.Open2
33Need to upgrade software.Open3
Workgroup_Master
Workgroup IDWokrgroup NameWorkgroup Owner
1Workgroup 13
2Workgroup 21
3Workgroup 33
User Master

User IDUser NameEmail idLocationUser TypeDepartment
1Daviddavid@acme.comPuneVIP2
2Frankfrank@acme.comBangaloreNormal3
3Mikemike@acme.comDelhiNormal1

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. 


Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.