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
mjohnson-TICmjohnson-TIC 

Trick: Allow inline view edit while overriding button edit to Visualforce Page

Hello All,

 

I recently ran into a situation where I wanted to use a Visualforce page to override new and edit buttons of a custom object. The issue was when I overrode the edit button, inline editing while viewing records of this object became disabled. Because this object had multiple page layouts, I did not want to deal with the daunting task of creating a custom Visualforce page with inline edit functionality for each of these layouts - not to mention the upkeep if anything needed changed. Initially it seemed like the solution would be easy enough, take the edit button off each page layout and replace it with a custom button pointing to my Visualforce page. Unfortunately I overlooked the fact most users edited records of this object by clicking the edit links next to each on the related list from account. 

 

The solution I derived was adding an html component to the left sidebar of all pages that is just a simple javascript snipplet that is working great. See below with my comments.

 

<script>

//retrieve first 4 digits of id to uniquely identify object
var pricing = window.top.location.href.substring(27,31);

//retrieve 2 characters after id to identify if in edit mode
var isedit= window.top.location.href.substring(42,44);

//check if object is in edit mode
if(pricing == 'a015' && isedit == '/e'){
//retrieve full object id and redirect to custom Visualforce page
var pid = window.top.location.href.substring(27,42);
window.top.location = '/apex/ProductPricingEdit?id='+pid;
}
</script>

 

I realize the implication that this may be poor design simply because this script must evaluate every page load on any screen, but for a few objects it is actually very light in comparison with everything else on the page that now has to load. Hope this helps some people out!