Tuesday, November 17, 2015

Two related list on one standard object - legitimate hack

We have account and contact look up relationship available in SFDC by default. On account standard page layout there is list of all contacts of that account are displayed .

One fine day client come up with requirement saying that he needs to separate contacts related list on account page layout. When contacts do not call field is checked it should appear in first related list otherwise it should appear in DND contact list(do not disturber).

We have multipal ways to achieve this:

1) Inline visual force page: We can develop VF page with standard controller and query all contacts and show them in separate lists.

Pros:
1) Meet the exact business requirement

Cons:
1) Not very flexible. If we want to change the criteria we will need to change the code.
2) Height of inline VF page is fix and if too many contacts are there then scroll-bar will appear on detail page


2) Add sorting: We can sort on do not call column and provide quick workaround.

Pros:
1) No coding required
2) very quick to implement

Cons:
1) Does not match exact requirement and its just workaround.


2) Two lookup hack: Third and best approach (in most of cases) is to add another lookup field on contact object which will refer account object. On this field add lookup filter. Do the same for standard account lookup filed.
After that last step is to update account page layout and add DND contact related list.

When you do that you will be able to show two contacts related list on account as bellow.




Pros:
1) No coding required
2) very quick to implement

Cons:
1) One extra lookup is required.