function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Greg RohmanGreg Rohman 

Inserting a custom related list between Account "Detail" and page layout-determined related lists?

Hello.

 

I'm looking for a way to customize the Account page to separate out Contacts based on the value of a field called "Inactive__c". Basically, I'd like to have all of the contacts with the value of the field as True in one list, and the value of the field False in another list.

 

I've created a custom page extension for Account,  I have the Apex code fully functional, and the custom lists are formatted and displaying properly on the VF page. My problem is getting the custom lists to appear between the account details and the rest of the related lists.

 

I could handle it like the following, where I'd have related lists turned off in the Detail section and then add them manually:

 

<apex:detail subject="{!Account}" relatedList="false"/>

<apex:pageBlock>Insert my custom lists here</apex:pageBlock>

<apex:relatedList list="Opportunities"/>
<apex:relatedList list="Expenses__r"/>

My problem with that, though, is that I have a number of different page layouts for the Account object, assigned to users in different roles. I'd much prefer to be able to use those page layouts to determine which related lists to display for each role, rather than having to do it with complex Apex.

 

Any suggestions or solutions would be greatly appreciated. Thank you.

 

-Greg


 

sfdcfoxsfdcfox

How about this solution?

 

Create two custom fields on Contacts, one called "Account (Active)" and the other "Account (Inactive)". Do not add the fields to the page layout. On the Related List name, call one "Active Contacts" and the other "Inactive Contacts." Add the related lists two the appropriate layouts.

 

Next, create a trigger on Contacts that blanks out the Account (Inactive) field while the Active box is checked, and copy the value from the Account field, and vice versa.

 

Finally, remove the New Contact button from the two custom related lists (or instruct your users that this button won't correctly fill in the account name, so they'll have to do it manually). Ideally, not having the buttons in place means they can use Create New from the side bar, or New Contact from the built-in Contacts related list to create a contact, because your trigger will correctly take care of the other two fields on the users' behalf.

 

Edit: I suggested this method because you can eliminate the need for VF pages altogether using this solution, requiring only one simple 6-8 line trigger, and the related lists will be freely customizable (change position of, per user or page, or remove entirely).

Greg RohmanGreg Rohman

HI sfdcfox, and thanks for the reply.

 

Thank you for the suggestion, but it seems like a complex method to achieve something that should be fairly simple.  If there's no other way, I may explore your suggestion, but I'm still hopeful there's a better way.

 

Thanks.

 

-Greg