Wednesday, 1 April 2015

Types of relationships that Salesforce provide
  1. Master-detail relationship
  2. Lookup
I assume that you are familiar with the difference between the two relations.
In this article we'll be using Master-detail relationship to implement one-to-one relationship.

  • Every department has only one manager
  • One manager can manage only one Department
Go to schema builder and create two objects Manager and Departments. Then create a Master-Detail relationship between the Department and manager.
Note: The relationship here is show by a line joining the two objects. The line diagram is quite intuitive. The multiple forks the end suggests the child objects.

As of now we have created a relationship where a department can have multiple managers, but that's not what we are looking for; hold on

To make a this relationship one-to-one we will be using rollup summary concept.
  1. Create a rollup summary field managerCount (count)  in departments, this will be auto populated depending upon the number of managers associated with that particular department.
  2.  Create a validation rule in department object on managerCount field. Throw an error "department can be managed by only one manager"when the managerCount is greater that 1.