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
Jago Peeters 9Jago Peeters 9 

How to hide standard "Submit for Approval" button

Hi,

We used to use a home page component (HTML Area) that had some javascript code to hide the standard "Submit for Approval" button on our custom object Contact Approval. This button was hidden because we use a custom button for the approval flow with some extra code behind. Since Summer '15 this hiding of the standard button is not working anymore.
Is there a way to remove this standard button from the Approval History related list?
Maybe with visualforce component on the home page? I tried but didn't manage to get it done.
On the following website I saw that it would not be possible anymore (see point 8): https://help.salesforce.com/apex/HTViewSolution?urlname=Home-Page-Components-Changes-Starting-Summer-14&

Please provide me with a solution, if there is any...

Thank you!

Kind regards
Jago
Best Answer chosen by Jago Peeters 9
JeeTJeeT

Hi Jago,

It seems that we need to customize all the links and buttons of salesforce standard relatedlist component. as said earlier is to take a help of a custom controller and update the vf page accordingly ( takes more dev time ). overriding by the help of javascript is not recomended as this is not reliable. ( takes less dev time ). If really works for you i would say great!!!

1.2.4. :- you have to work arround with javascripts. Do you know I did it for you :)
 

<apex:page StandardController="Opportunity" showHeader="false" tabStyle="opportunity">
 <apex:includeScript value="{!$Resource.jQueryMin1dot3}"/>
 <style>
     /* to hide submit for approval button */
     input.btn[name="piSubmit"] {
            display: none;
     }   
      /* to hide recall button */
     input.btn[name="piRemove"] {
            display: none;
     }          
 </style>
 <apex:form>
     <input value="Recall Approval Request" id="recall" class="btn" type="button" title="Recall Approval Request"/>
 </apex:form>
 <apex:relatedList list="ProcessSteps"/>
 
 <script>
     var jeet = $.noConflict();
     jeet(document).ready(function(){
         jeet('a').each( function(){             
             if(jeet(this).text().trim().indexOf('Show') != 0){     
                 var addr =  ''+jeet(this).attr("href");             
                 var idx = addr.indexOf('retURL');
                 if(idx != -1)
                  addr = addr.substring(0,idx)+'retURL='+'{!Opportunity.Id}';
                 jeet(this).attr("href", "#");
                 jeet(this).bind( "click", function() {
                      window.parent.location= addr;
                 });
             } 
         });
         jeet('.tertiaryPalette').css("background-color", "#ddb929");
         jeet('.secondaryPalette').css('border-top', '3px solid #ddb929');         
     });
     function correctRetURL(s){
         var idx = s.indexOf('retURL');
         if(idx != -1)
          return s.substring(0,idx)+'retURL='+'{!Opportunity.Id}';
     }
 </script>
</apex:page>
3.
  • Remove all the standard button from the related list using css tricks which i have shared before.
  • Add your custom button on the visualforce page and  on the action method by the help of [SELECT Id, ProcessInstanceId, ProcessInstance.TargetObjectId FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId =: oppID]; you can get to know recall button will be available or not. if it returns a record then show the button so prepare an url "/04i90000009lwcT(Process id by soql )/e?et=REMOVE&retURL=0069000000fBh20 (current opportunity id)"  
  • OR if you want to do it by JS add these method inside the ready call
  • jeet('.pbButton input').each(function(){
                 if( jeet(this).attr('name') == 'piRemove' ){
                     var addr = ''+jeet(this).attr('onclick');     
                     var testUrl = addr.match(/'(https?:[^\s]+)'/);
                         addr = testUrl && testUrl[1];          
                     var idx = addr.indexOf('retURL'); 
                     if(idx != -1)
                      addr = addr.substring(0,idx)+'retURL='+'{!Opportunity.Id}';                 
                     addr = addr.replace('navigateToUrl','window.parent.location=' );                  
                     jeet('#recall').bind( "click", function() {
                          window.parent.location= addr;
                     });             
                 }
             });

    Seems almost I did you project... Enjoy.. 

Thanks
Jeet

All Answers

ManojjenaManojjena
Hi Jago ,
I think if you will remove from page layout then the standrad Submit for approval will be hidden for the all record .Then you can add custom button for submit for approval .

Please correct m eif I am wrong .

 
Jago Peeters 9Jago Peeters 9
Hi Manoj,

Thanks for your quick reply.

The custom button is already added (on the detail section of page layout, not on the related list).
Since Summer '15 release, the standard button on the Approval History related list is visible again, before we made it hidden through home page component html area.
We need the Approval History related list, only the standard button "Submit for Approval" needs to be hidden (or removed) from the page layout.

I thought that this could now be done through a VF page that can be added as VF area on homepage component but I don't know exactly how.
Therefore I raised the question here...

Kind regards
Jago
JeeTJeeT

Hi Jago,

I have one idea, it may help.
You can override view with custom VF Page. and statard components are available to bring up detail page and related lists into custom VF page. There is an article from my Blog http://jeetforce.blogspot.in/2014/09/how-to-remove-standard-button-loading.html (http://jeetforce.blogspot.in/2014/09/how-to-remove-standard-button-loading.html" target="_blank).

Let me know if it helps

Jago Peeters 9Jago Peeters 9
Hi JeeT,

Thanks for your suggestion.
I prefer not to do that, only in worst case scenario.
But I thought that this could be solved in an easier way. Create a VF page with only a piece of code that hides te button. And add this VF page as a VF area on homepage component. I have read somewhere that this should work but I don't know the exact code.

Can somebody help me with this?

Kind regards
Jago
JeeTJeeT
Hi Jogo,
Sorry for replying Late.
From the recent salesforce releases, VF Components on Home page components loads with an iframe, So it will be difficult to run a JS code to override a button in parent DOM. So i have an Idea for this type of requirement which is:
  • Create a Visualforce Page with this following code.
<apex:page StandardController="Opportunity" showHeader="false">
  <style>
     input.btn[name="piSubmit"] {
            display: none;
     }
 </style>
    <apex:relatedList list="ProcessSteps"/>
</apex:page>

The stylesheet class overrides submit for approval button. Run (with id as parameter e.g. '/apex/you_vf_name?id=00628000002c50v') the vf page to verify
  • Remove Approval History related list from the Page Layout and add this vf page as a inline vf page on the page layout. which will look as similar as below sample screenshot (Notice that the related list loads without "Submit for Approval" button)
Approval History related list Without "Submit Approval" button
Note: If you have find any solution for this requirement, Kindly share. Or if this soution matches your requirement, Kindly mark this as Best Answer

Thanks
Jeet
Anirban RoyAnirban Roy
Jeet,

Many thanks for the above solution. It worked. I just changed the name of the section to Related Lists as well, to make things look bit more logical. Came in right time.

Thanks again!!

Roy
Jago Peeters 9Jago Peeters 9
Hi JeeT,

First of all, sorry for my late reply. Was working on other projects and now the question regarding this button came up again.
So I tried your solution and it works fine. Thanks for that.

I just have 1 question. If you look at below screenshot, first Approval History section is the VF Page as you suggested, second Approval History section is the standard one.
Everything looks the same except for the orange rows (the titles). The text (e.g. Step: Step 1 (Pending for first approval)) is in white, which in both cases fine. It's only the orange background color for those rows that is not taken over in the VF Page. This is the only blocking issue for us to deploy.

Any idea on how to solve this?

User-added image

Many thanks in advance!

Kind regards
Jago
Jago Peeters 9Jago Peeters 9
Just 1 other question. When I click the Approve/Reject link or Reassign link, I'm navigated/directed within my inline VF Page. Can I force the system to open within the same tab (so actually override the screen)? So therefore the screen is refreshed automatically and always showing the correct page in a good layout.

Thanks!
Jago
JeeTJeeT
Hi Jago,

Nice catch for the link redirection and the background css. (y) 
spent some time behind this and finally get to know
  • alternative of onclick events of the hyperlinks is to add a custom controller, query the the processinstance items and display in a table with links and open it in parent window. which may involve some customization and adding some js codes. but adding a custom controller is also time taking and may include a test class for it or may stetch you dev time.
  • reason of background-color is that the "dStandard.css" file is loading on the inline vf page, but somehow it is not getting called from the tr element. so the css background is missing and showing as default black. no alternative; forced to add some js code.
from all work-arround involved adding js codes, finally thought of to add JQUERY codes to achieve the goal. disadvantages can be causing some cases like: if the jquery file conflicts with some-other or if it fails to load, then this solution may not work. but these are very rare.

Here is:
<apex:page StandardController="Opportunity" showHeader="false">
<!-- Add the JQuery library into your static resourses -->
 <apex:includeScript value="{!$Resource.jQueryMin1dot3}"/>
 <apex:relatedList list="ProcessSteps"/>
 <style>
     /* to hide submit for approval button */
     input.btn[name="piSubmit"] {
            display: none;
     }     
     /* to hide recall button */
     input.btn[name="piRemove"] { 
            display: none;
     }     
 </style>
 <script>
     var jeet = $.noConflict();
     jeet(document).ready(function(){
         jeet('.actionLink').each( function(){
            var addr =  jeet(this).attr("href");
             jeet(this).attr("href", "#");
             jeet(this).bind( "click", function() { window.parent.location= addr; });
         });
         jeet('.tertiaryPalette').css("background-color", "#ddb929");
         jeet('.secondaryPalette').css('border-top', '3px solid #ddb929');
         //if you recuirement is not show any button, then remove the styles from above and add/uncomment below statement
         //jeet('.btn').css('display', 'none');
     });
 </script>
</apex:page>
_____________________________________________________
If it fulfil your requirement, kindly :) and mark this as a best answer
 
Jago Peeters 9Jago Peeters 9
Hi JeeT,

Many thanks for your solution. It works correctly for Approve and Reject links. The colors in the title rows are there which is great.

Unfortunately some other links and buttons are not behaving like it should:
1. Show more link: colors are gone
2. Go to list link: page is opening within the inline VF page
3. Recall button: page is opening within the inline VF page
4. Reassign link: page is opening correctly but if you click "Reassign" or "Cancel" buttons it's navigating to the VF page itself (due to the retURL as you can see in the link that is used: https://cs17.salesforce.com/04ig0000000Yjfn/e?et=REASSIGN&retURL=%2Fapex%2FCA_Without_Standard_Submit_Button%3Finline%3D1%26id%3Da0Yg0000001LKpd)

Would you be able to find a fix for these 4 issues? That would be wonderful.

Thanks in advance!

Kind regards
Jago
 
JeeTJeeT

Hi Jago,

It seems that we need to customize all the links and buttons of salesforce standard relatedlist component. as said earlier is to take a help of a custom controller and update the vf page accordingly ( takes more dev time ). overriding by the help of javascript is not recomended as this is not reliable. ( takes less dev time ). If really works for you i would say great!!!

1.2.4. :- you have to work arround with javascripts. Do you know I did it for you :)
 

<apex:page StandardController="Opportunity" showHeader="false" tabStyle="opportunity">
 <apex:includeScript value="{!$Resource.jQueryMin1dot3}"/>
 <style>
     /* to hide submit for approval button */
     input.btn[name="piSubmit"] {
            display: none;
     }   
      /* to hide recall button */
     input.btn[name="piRemove"] {
            display: none;
     }          
 </style>
 <apex:form>
     <input value="Recall Approval Request" id="recall" class="btn" type="button" title="Recall Approval Request"/>
 </apex:form>
 <apex:relatedList list="ProcessSteps"/>
 
 <script>
     var jeet = $.noConflict();
     jeet(document).ready(function(){
         jeet('a').each( function(){             
             if(jeet(this).text().trim().indexOf('Show') != 0){     
                 var addr =  ''+jeet(this).attr("href");             
                 var idx = addr.indexOf('retURL');
                 if(idx != -1)
                  addr = addr.substring(0,idx)+'retURL='+'{!Opportunity.Id}';
                 jeet(this).attr("href", "#");
                 jeet(this).bind( "click", function() {
                      window.parent.location= addr;
                 });
             } 
         });
         jeet('.tertiaryPalette').css("background-color", "#ddb929");
         jeet('.secondaryPalette').css('border-top', '3px solid #ddb929');         
     });
     function correctRetURL(s){
         var idx = s.indexOf('retURL');
         if(idx != -1)
          return s.substring(0,idx)+'retURL='+'{!Opportunity.Id}';
     }
 </script>
</apex:page>
3.
  • Remove all the standard button from the related list using css tricks which i have shared before.
  • Add your custom button on the visualforce page and  on the action method by the help of [SELECT Id, ProcessInstanceId, ProcessInstance.TargetObjectId FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId =: oppID]; you can get to know recall button will be available or not. if it returns a record then show the button so prepare an url "/04i90000009lwcT(Process id by soql )/e?et=REMOVE&retURL=0069000000fBh20 (current opportunity id)"  
  • OR if you want to do it by JS add these method inside the ready call
  • jeet('.pbButton input').each(function(){
                 if( jeet(this).attr('name') == 'piRemove' ){
                     var addr = ''+jeet(this).attr('onclick');     
                     var testUrl = addr.match(/'(https?:[^\s]+)'/);
                         addr = testUrl && testUrl[1];          
                     var idx = addr.indexOf('retURL'); 
                     if(idx != -1)
                      addr = addr.substring(0,idx)+'retURL='+'{!Opportunity.Id}';                 
                     addr = addr.replace('navigateToUrl','window.parent.location=' );                  
                     jeet('#recall').bind( "click", function() {
                          window.parent.location= addr;
                     });             
                 }
             });

    Seems almost I did you project... Enjoy.. 

Thanks
Jeet
This was selected as the best answer
Jago Peeters 9Jago Peeters 9
Hi JeeT,

Thanks for your feedback. I applied it and customized it a little bit to specify my requirement.

I will mark your last reply as best answer but your previous replies were also very helpful ;-)

Thank you again for everything. Talk to you next time on another topic :-)

Kind regards
Jago