Reporting and Dashboards Blog

Reporting and Dashboards Blog

Junction objects in salesforce.com

Thomas Tobin Oct 8, 2007

 

Hiding or politely staying out of the way?

Sometimes in salesforce.com, there are objects that you don't see.
Examples of these junction objects are:

  • the link between opportunity and contact (the contact role)
  • the partners in opportunities
  • the accounts linked to an account as partners.

All of them are kind of visible in the interface and the detail pages and reports currently, but are much more visible in Custom Report Types.

Junction objects and what they do

Junction objects are part of the set of objects in salesforce that join one object to another. Specifically, junction objects are used to join many objects on one side to many on the other. For instance, if you have a Contact, it can be attached to many Campaigns. So you might expect a campaign list as a related list on the Contact detail page. But equally, a campaign can cover many contacts. So, the junction object is used to link the Campaign to a Contact. In the case of the Campaign Member - this junction object - it also has some attributes of it's own - for instance, when the recipient responded.

The Campaign Member junction objects in Custom Report Types

When you see the Campaign Member table, you see it in two ways, depending on the direction you look:
From Contacts to Campaigns, we see the Campaign History object
From Campaigns to Contacts, we see two alternatives:

  • Campaign members - which is both leads and contacts, but since there is no combined object or page layout, few lookups and no related lists
  • Contacts - for contacts only, and all its lookups to other objects and related lists of other records

When we look from Contact to Campaign History, the fields

  • First Responded (Date)
  • Responded (Y/N)

Will be present on the Campaign History.

When we look from Campaign to Contact, these same fields are on the Contact view.
But why?

To make it like the related list views you already see when looking at these records.

Other junction objects

Additional behavior of this type can be seen:
Between

  • Accounts and
    • Accounts when using the Partner Account relationship
    • Users for Sales Team
    • Territories (if you are using Territory Management, and in Winter'08)
  • Campaigns and
    • Leads and vice-versa
    • Contacts and vice-versa
    • Campaign Member
  • Cases and
    • Solutions and vice-versa
  • Opportunities and
    • Contact Roles (which is Contacts and the Role they play in the deal) and vice-versa
    • Partners (which are really accounts)
    • Products (which actually in CRT is a bit more complicated - see the post  )
    • Sales Team (back to user)

In all these cases, the Custom Report Type is behaving just like the related lists you'd see on the detail page of a record of one of those objects.

Making your own junction object

You can also build junction objects for yourself - between standard or custom objects. If you want to make your own man-many link between two objects, you can make a custom object, and add one field as a lookup to the first object, then another field as a lookup to the second object.
If you want the junction object to go away automatically when one of the parents is deleted, then make your junction object a detail of that object.
For instance, imagine you have:

  • Customers
  • Cars
  • Test drives, where customers test drive a car.

When a customer goes away and is deleted, you don't care any more about the test drives they did, and they will be deleted too.

  • you would create the Customer object (or maybe use Contact)
  • you would create the Car object
  • you would create a "Test Drive", and
    • add a new field of type lookup to Car
    • add a new field of type master-detail, pointing to Customer
    • you might add more fields about this test drive - for instance, the date of the test-drive, and who took them on the test drive

The Report Type for your custom junction object

Now you can make a report type. The business user decides:
We care about the Customers most and what cars they test drove. If there were cars that weren't driven, we don't care about them in the report.

We could start with Customer, or Car. Since we care most about Customers:

  • Start with the primary object Customer
  • in the next step of the wizard, choose "Test Drive"
  • Save the Custom Report Type
  • Now Edit the layout
  • Choose "Test Drive" in the object chooser, and click "Add fields via lookup"
  • click "Car"
  • now chose the fields from there

Possible Reports for your object

using this, the business user can see:

  • Which cars are the most popular (most test drives)
  • Which customers are just test driving a lot of cars (and not buying)
  • Which customers test drive the same car a couple of times (maybe it's time to lower the price)
  • which rep used which cars most (is somebody always trying to sell the V8 with leather seats?)

And you've used a junction object to be able to answer those questions.

Now, for your business, which questions could be answered if you used junction objects to look at the relationships between things?

 

0 Comments

Post a comment