3

I need to add some JS to some salesforce standard edit pages to allow us to add functionality to aid in data entry.

I would like to do it the "correct" way and my salesforce knowledge isn't great. I have however read all I can find and established that up to recently (last few days?) you could add a widget to the sidebar that would inject JS onto every page or edit pages etc but this seems very hacky and as I mentioned seems to have been disabled now.

The option that seems to be the best and most supported is to add a new VisualForce page and that uses the standardController for the page you want (for example "Contact") then include the default page for example:

<apex:page standardController="Contact">
    <apex:detail inlineEdit="true" />
</apex:page>

and then throw in the JS to do the work or maybe some kind of include of the JS resource? like:

<apex:includeScript value="{!$Resource.example_js}"/>

Now a few quick tests using something like:

<apex:page standardController="Contact">
    <apex:detail inlineEdit="true" />

    <script type="text/javascript" language="Javascript">
        alert('Do stuff here...');
    </script>
</apex:page>

Which appears to work fine for the in-line edit option but I really want to use it for both the main edit page and the new page (might be the same). This is where I have hit a brick wall as I can't find out how to build a page the "inherits" the standard edit/new page.

I don't want to be creating custom pages as this would mean that any already configured custom fields wouldn't be there and would make adding/removing fields require the VisualForce page to be updated (not the easy drag and drop of the standard page editor!)

So to conclude: I want to add custom JS to a lot (all if easier?) new/edit forms the "right" way. I don't mind creating custom VisualForce pages for each of the edit pages BUT the new pages MUST just have the same layout etc as the original pages and update when they do. :) I'm SURE that's not to much to ask? ;)

Thanks

P.S. Please assume I have no knowledge of salesforce and point me to any info required for the solution as I really only started using salesforce Monday! ;)

  • There is no clean way to add JavaScript and that JavaScript will have to rely on details of the generated HTML that are not part of Salesforce's APIs meaning those details may change in the future and break the JavaScript. What are you trying to accomplish in the JavaScript? There may be alternative approaches to solving your problem that are more cleanly supported in the platform. There are also 3rd party solutions for better UI such as Skuid. – Keith C Oct 3 '15 at 0:09
  • @KeithC Thanks with all JS (or any kind of plug-in) added to existing site or system we don't control there is the risk of an update causing the code to stop working and that is fine. We monitor and test new updates and can update the plug-in if/when this occurs. What I am trying to do is reduce the chances that the JS won't be loaded at all which is a much harder job to fix quickly. I also don't want to be fighting SalesForce on this. We are trying to add our data input validation and autofill system. :) It basically works like the Google Instant search so as you type it gives you surgestions – GazB Oct 5 '15 at 8:27
  • I don't think this is a duplicate of the ones pointed out at the top. Those are trying to add JS to an existing form and my question makes it clear I am open to creating custom VisualForce pages for each of the edit pages BUT the new pages MUST just have the same layout etc as the original pages and update when they do. I just haven't been able to work out how to do the edit form this way yet. – GazB Oct 5 '15 at 8:30