One function we would love is to not show the convert button on the lead unless it's the right time to convert (ie. the correct stage with all data gathered).

I have created a Lightning component which can easily modify the CSS of the lead page. However, I am struggling implementing the JS side which I want to find the Convert button and hide it.

this works in Jfiddle and browser extensions, but not in salesforce itself. Something is getting in the way. Any ideas?

    function HideConvert() {
      var elements = document.querySelectorAll('[title=\"Convert\"');
      for (var i = 0; i < elements.length; i++) {
           elements[i].style.display = "none";
  • why don't use record type with different page layout instead of doing this hack. – Tushar Sharma Oct 21 '16 at 7:21
  • Because every record type needs a convert button. I don't like having mutliple page layouts to get around the lack of dynamic field choices. – Daniel Howell Oct 21 '16 at 9:08
  • I think you need only two page layout one with button and one without – Tushar Sharma Oct 21 '16 at 9:18
  • You cannot modify or override the standard functionality, may be you can opt for custom button. even i tried few day ago for one page button java script functionality and not able to disable it using this.disable – Raj_SFDC Oct 21 '16 at 15:51
  • Hey Daniel, were u able to find a solution for this ? – sf_user Jul 5 '17 at 14:07

Use aura:Id https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_find_by_id.htm


addClass() on the button depending on the criteria you have https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_styles.htm

  • Thanks for the reponse. These are standard elements and they don't have ids. Instead I need to find them on the element title – Daniel Howell Oct 21 '16 at 7:08
  • <div title="Convert" data-aura-rendered-by="125:300;a">Convert</div> – Daniel Howell Oct 21 '16 at 7:08
  • You can give them an html property and then use JS to find the element using that property – d_k Oct 21 '16 at 7:09
  • Once again they are standard fields and I cannot change any of that html – Daniel Howell Oct 21 '16 at 7:11

I managed to solve it with some clever thinking. Security restrictions make it difficult to edit the DOM outside of the component.

BUT, CSS works just fine. So I created a blank style tag:

Then my JS just added and removed styles: document.getElementById("ConvertStyle").innerHTML = "a[title*=\"Convert\"], a[title*=\"Convert\"]:hover{ display:none;}";

  • This hack will stop working, so please don't do this. You interact with components in other namespaces via their interface. Imagine if every component tried to change the DOM of a standard component, some hiding it and another one showing it. What would happen? Your component doesn't own the page, it has to share the page with other components that you don't control, so unless your goal is to have your component break the page for all the other third party components, stick to changing your own DOM and don't try to break standard components that don't belong to you. – Robert Sussland Oct 22 '16 at 5:15
  • I believe the op is just trying to solve for a use case that sf does/will not support. One could argue that if it is the op own org then the dom does indeed belong to the op in that they can hack it at will as long as they know it will potentially break. Now if this was for a managed package I agree completely. Are you saying there is a way to interact with the standard ns to hide the button. Not sure why you would say that if it does not exist. – Eric Oct 22 '16 at 6:11
  • Add global actions to lightnign components will come in the next two years and I will have a proper solution. In the mean time we hack. Just like URL hacks are are worse idea than CSS hacks they are still common place until actions work for enough things (note I don't use URL hacks any more as SF gave us a solution,yay) – Daniel Howell Oct 22 '16 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.