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
LavanyaLavanya 

How to disable a Custom Button once it is clicked.

Hi I am having a custom button"Convert", I need to disable this button once it has clicked. Kindly anyone tell how resolve this either by apex code & Visualforce code. Kindly reply me to resolve this issue.

 

Thanks ,

Regards,

Lavanya.

AnushaAnusha
in VF Page, for Command Button there is attribute called disabled

<apex:commandButton action="{!Convert}" value="Convert" disabled="{IF(LeadObj.IsConverted==true,true,false)}"/>
LavanyaLavanya
its not working, i need to hidden that convert button once it has converted the record into account and contact. Next time when click this convert button it should not do conversion.
Thanks ,
Regards,
Lavanya.
ManjunathManjunath

Hi,

 

Try this,


<apex:commandButton action="{!Convert}" value="Convert" rendered="{!IF(Lead.IsConverted==true,false,true)}"/>

This will remove that button from the page, if it is converted.

 
Regards,
 
Raj.ax1558Raj.ax1558

Hi 

eg.

<script>

function callConvertMethod()

{

Convert();

}

function hideButton()

{

document.getElementById('{!$Component.buttonDiv}').style.display="none";                  //Please enter here proper full id. 

}

</script> 

 

<Apex:actionfunction action={!convertMethod} name="Convert" oncomplete="hideButton()"/>

 

<div style="display:block" id="buttonDiv">

<input type="button" value="Convert" onclick="callConvertMethod"/>

</div>

 

 

 

2) Using flag variable, this flag variable is boolean type. You need to flag value is true at the starting then on complete of action method you can call another action method, and from this method you can  set value is false of this flag variable. for hidding the button.

used this variable in command button

 

<apex:commandButton value="convert" onclick="ActionFunctionName" rendered="{!flag}"/>

 

 

if you find this as solution, Please mark as solution for the other help on a same query. 

 

Thank you,

Raj Jha

vriavmvriavm

I Use this always:

<apex:commandbutton value="Sample Example" onclick="disableButton(this);" onComplete="enableButton(this);" action="<Some Action method call>" rerender="<Rerender some components in page>"/>
<script language="javascript">
function disable(obj) {
if (obj) {
obj.disabled = true;
obj.style.color = '#C0C0C0';
}
}
function enable(obj) {
if (obj) {
obj.disabled = false;
}
}
</script>

 

Thanks & Regards,

Vivek V.

LavanyaLavanya
hi Manjunath, thank for your reply. Its not working i am getting this
Error: Unknown property 'CustomLead__cStandardController.leadObj'.
Can anyone tell how to resole this issue
LavanyaLavanya

I am having a custom button "convert" once i click that that button i will create an account & contact. Then once again i went to the same record now i want the convert button show be disable because that record already convert.can anyone tell how resolve this
vriavmvriavm

Hi,

 

Is it a out of the box page or a VF page (Page where convert button is in)??

 

If it is a out of the box page then you can do a javascript message on button lick. 

If it is VF page You stamp a flag (isconverted) in the record where it is set when user clicks on this button first time. Then on the rendred proprtty of the Convert button refer to this field in the flag and set true/false for this rendered property.

 

Thanks & Regards,

Vivek V.

Gmail: vriavm@gmail.com

LavanyaLavanya
Hi vriavm, thanks for the reply. this is my visual force page code

<apex:page standardController="CustomLead__c" cache="true" action="{!convertlead}" extensions="LeadConversion" >

<br/><br/>
<apex:messages style="color:red; font-weight:bold; text-align:center;"/>
<apex:form >
<center>
<apex:outputField value="{!CustomLead__c.Name}" rendered="false"/>
<apex:outputField value="{!CustomLead__c.CompanyName__c}" rendered="false"/>
<apex:outputField value="{!CustomLead__c.LastName_c__c}" rendered="false"/>
<apex:outputField value="{!CustomLead__c.opp_name__c}" rendered="false"/>
<apex:commandLink value="Redirect to Lead" style="color:blue; font-weight:bold;" action="{!RedirectToLead}"/>
</center>

</apex:form>
</apex:page>

In this what changes i need to do for this.
ManjunathManjunath

Which is the button you want to hide/disable in the above code.

I dont see your convert button.

LavanyaLavanya
Hi Manjunath, thanks for your reply. I am one custom button "convert", i need that button should be disabled once the record as created. I have pasted the VF code. In that what is change i need to do.
ManjunathManjunath
Hi,

Where is the code. In the previous post there is no convert button.

Regards,
LavanyaLavanya
<apex:page standardController="CustomLead__c" cache="true" action="{!convertlead}" extensions="LeadConversion" >

<br/><br/>
<apex:messages style="color:red; font-weight:bold; text-align:center;"/>
<apex:form >
<center>
<apex:commandButton action="{!convertlead}" value="Convert" disabled="true"/>
<apex:outputField value="{!CustomLead__c.Name}" rendered="false"/>
<apex:outputField value="{!CustomLead__c.CompanyName__c}" rendered="false"/>
<apex:outputField value="{!CustomLead__c.LastName_c__c}" rendered="false"/>
<apex:outputField value="{!CustomLead__c.opp_name__c}" rendered="false"/>
<apex:commandLink value="Redirect to Lead" style="color:blue; font-weight:bold;" action="{!RedirectToLead}"/>
</center>

</apex:form>
</apex:page>
ManjunathManjunath

Hi,

 

Since you are using a custom object, create a custom field called isconverted(Checkbox) in that object.

Next after the account record and contact record is inserted, then in your custom functionality make this isconverted to true.

 

Now in your vf page

<apex:commandButton action="{!convertlead}" value="Convert" disabled="{!if(CustomLead__c.isconverted__c==true,false,true)}"/>

 

Regards,