Sunday, 4 October 2015

Workaround for removing the Save&New button from Standard pages after Winter'16 release

As you all know earlier Salesforce replaced the rich text editor in HTML Area home page components with a new version that supports more markup but doesn’t allow HTML to be manually entered.
So as a workaround, we used custom links in home page components to invoke our scripts, See the below link for details.

Since this workaround was only supported till Summer'15 and we are now in Winter'16 so this wont work because now sidebar script does not automatically invoke and requires a manual click on the link to invoke it. See this link for details

With the new UI, the sidebar is going to go away. So, the less reliance we have on the sidebar components, the better it would be for our transition.

However, there isn't any other way to hide the "Save & New" button but to replace it by using a Visualforce page. Salesforce has been taking security as the highest priority and been striving to avoid any kind of hacking activities (including Javascript workarounds) which could incur potential security thread to customers. That's the reason why Javascript is no longer supported within a home page component.

After discussing with Salesforce, the workaround I've found is to override the "New" button of an object using a Visualforce page which has a Controller to check if the "Save & New" is clicked. If it's clicked then ignore the "New" action and just do "Save". So even the "Save & New" button is still visible but it would just behave like the "Save" button.
The following are the sample code which works on the Account Object. To see it in action simply goto Setup | Customize | Accounts | Buttons, Links and Actions | Edit the "New" button by the following Visualforce page.

Visualforce Page:

<apex:page standardController="Account" extensions="SObjectNewActionOverrideController" action="{!onLoadPage}">
public class SObjectNewActionOverrideController {

    public String debug{get;Set;}
    private String SObjectPrefix = null;
    public SObjectNewActionOverrideController(ApexPages.StandardController controller){
        this.SObjectPrefix = controller.getRecord().getSObjectType().getDescribe().getKeyPrefix();
    public PageReference onLoadPage(){
        this.debug = JSON.serializePretty(ApexPages.currentPage().getParameters());
        String retURL = ApexPages.currentPage().getParameters().get('retURL');

            && retURL != null
            && retURL.startsWith('/'+SObjectPrefix)
            && retURL.indexOf('/', 4) < 0
            && !retURL.contains('?')
            && retURL.length() >= 15){
            PageReference pg = new PAgeReference(retURL);
            return pg;
            PageReference pg = new PAgeReference('/'+this.SObjectPrefix+'/e');
            for(String key : ApexPages.currentPage().getParameters().keyset()){
            if(key == 'save_new' || key == 'sfdc.override') continue;
                pg.getParameters().put(key, ApexPages.currentPage().getParameters().get(key));

        return pg;

1 comment: