On Opportunity, I've created a related object called Opportunity Item. On the details page for an opportunity, a related list was automatically added for Opportunity Items.

I need to take complete control over the way this list is presented either by configuring it, or by replacing it.

I don't know how I should do this in Salesforce or what the best choice is for my needs. I'm looking for suggestions and examples from other devs that have had to do this.

On each row of Opportunity Items :-

  • I can't have a delete link shown.
  • I want to "roll up" data from a collection of objects under Opportunity Item (which could be different depending on data. This might mean the number of columns vary.
  • I want the "edit" link to go to a custom page for editing the Opportunity Item
  • I want the "New Opportunity Item" button to take me to an apex page for creating a new Opportunity Item, not the default edit page.
  • It might be necessary to have the data in a paged table view.

Without this, the Opportunity Items section of the Opportunity Details page is as good as useless.

I tried this by using an apex page embedded into the Opportunity details page, but it looked terrible, and wasn't enough room (height) on the Opportunity Details page to display all information from the embedded page.

I've found a few Salesforce/Apex/VisualForce bloggers to have helpful content, but nothing that seems to quite fit the bill, though I'm not sure how to term what I'm looking for.

You basically have four options with all of them having advantages and tradeoffs:

  1. Stick with standard related list: This is the easiest way but also the one with the most restrictions. But in my experience you can achieve most of your requirements. You will have to accept some restrictions especially the design and layout. I won't cover all details about how to solve each point but try to give you hints if it's possible at all. Possibly ask separate questions to particular points

    1.1 delete link: see @sfdcfox or use JavaScript attached to a custom button to hide them

    1.2 dynamically variable columns: I doubt it's possible

    1.3 custom edit page: standard functionality, override the edit page

    1.4 new button to custom page: as 1.3

    1.5 won't be really paged as you have in mind but the standard with 'show (always) more' is somehow acceptable for many use cases.

  2. Embeded a visualforce page:

    2.1 here you already encountered it's most annoying aspect that the height isn't adjusted automatically. This can be overcome with workarounds described here

    2.2 in general you will find it uncomfortable to have your page boxed in an iframe which can't interact easily with the top frame due to the browser's XSS protection.

  3. Override the entire view: this option brings you the greatest customizability but it's also the most radical approach.

    3.1 typically you'll place you the existing layout on it using an apex:detail an then you'll add e.g. a apex:datatable for your custom full-featured related list.

    3.2 advantage is: there is no iframe jail

  4. Hybrid approach: use stanard related list and boost it a bit with a locally injected JavaScript using the method described here Changing the color of a custom button

    • This method is less invasive than 2 and brings you almost the same flexibility.
    • Today I used this to colorize the list rows on certain conditions, but you can do anything
    • I would load jquery to make things easier but you could use also plain js
    • if you craft your code carefully as a nice benefit your improvements will also render in the hover-links on the top of the page. I was surprised to see my colorization even there and it looks awesome

So which way to choose?

  • Try to make compromises and sick with 1.
  • If you can't use 1. best practices are to use 3.
  • my personal favorites are still 4. and 2. but you have to be aware about possibly implications

I can't have a delete link shown.

Remove the delete record permission from profiles that shouldn't be deleting those records.

I want to "roll up" data from a collection of objects under Opportunity Item (which could be different depending on data. This might mean the number of columns vary.

You can make roll up summary fields, and display up to 10 such fields (or any fields you like), in the related list. You can't choose which fields to show based on the child records, but you could use different record types on the opportunity to control which fields appear.

I want the "edit" link to go to a custom page for editing the Opportunity Item

Using a page with "standardController" set to your custom object name, you can go to the custom object detail page, go to Standard Buttons and Links, and override the Edit page.

I want the "New Opportunity Item" button to take me to an apex page for creating a new Opportunity Item, not the default edit page.

You can override this page as well (in fact, it could even be the same page, if you wanted to), but it can be independent of the edit setting, above.

It might be necessary to have the data in a paged table view.

In the related list, Salesforce automatically offers paging only when the list exceeds the user's current related list size setting (default 5). You could also write your own paging mechanism if you wanted to.

  • Hi Mr. Fox, if you use the standard related list on a standard layout, is it possible to use an own paging mechanism? – Uwe Heim Aug 29 '14 at 0:00
  • Nope. If you use the standard related list, you must also accept the standard pagination. – sfdcfox Aug 29 '14 at 1:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.