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.

Scenario
  • 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

Solution
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.


7 comments:

  1. Great idea! Thank you for posting it!

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. what is the code in validation rules?

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete