[SalesForce] Remove submit for approval button once the record is recalled

My client requires to remove submit for approval button once the record is recalled.

We have a triger that forces record to move to submit for approval depending on the stage status. and approval process critearea is has to be at certain stage to allow submit for approval .

So once it is recalled the status changes to the lower level and at that point submit for approval thing does not work because not meeting the criteria of approval process.

So I need that button to be removed completly once the record is recalled.

Best Answer

Thanks to this wizard's answer in the below question, based on which I am framing my answer to pull of this trick (Do not blame if SF stops supporting or jacks up JS support as they did with home page components):

Changing the color of a custom button

Step 1: Create a fake submit for approval (or) name it anything you want

Step 2: I have the logic to hide the button based on stagename, you can use your any field and make this button disappear conditionally on page load.

Paste this javascript in the base64 encoder

http://rot47.net/base64encoder.html

(function() {
var buttontohide = document.getElementsByName('submit')[0];
var fakesubmitbutton = document.getElementsByName('submit_for_approval_custom')[0];
var stage = $("[id$=opp11_ileinner]").text();
buttontohide.style.visibility = 'visible';
fakesubmitbutton.style.visibility = 'visible';
if(stage== "Prospecting"){
  buttontohide.style.display= "none";
  fakesubmitbutton.style.display= "none";
}
else{
fakesubmitbutton.style.display= "none";
}
}());

Step 3: Add this new button to the page layouts of the users who you wish to disable the submit for approval button.

Button syntax should look like : enter image description here

Final output:

when stage = prospecting ( submit for approval is not visible)

enter image description here

when stage != prospecting the submit button is visible. enter image description here

Related Topic