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
RobotiRoboti 

How to disable a custom button after one click?

Hi,

 

We have a custom button on the detail page of a custom object. This button is used to open URL of another application and populating the object field in the other application.

 

Current Behaviour of button - Display in new window

Content Source - URL

 

It should not be allowed that the button is clicked again (in this case, data will be sent to other application again). 

For this we have created a checkbox field which will be FALSE and it should be turned to TRUE after the first click of the button.

 

Also, How to check the field value, change it to TRUE (if it is FALSE), and send the data to other system by opening the URL of that system on one click of this custom button?

 

Please help!

Thanks and Regards!

hitesh90hitesh90

Hi,

 

we can't disable the button but we can show alert message after the checkbox to TRUE.

for that you have to use "Execure JavaScript" instead of "Display in new window".

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

RobotiRoboti
Hi Hitesh,

Thanks for your solution! We are into Salesforce configuration only. How can we check the field value, change it to TRUE (if it is FALSE), send the data to other system by opening the URL? Also, if the value of checkbox field is TRUE (after first click), how can we show an alert message?

Thanks in advance!
hitesh90hitesh90

Hi,

 

 

It's configuration. see below example

 customize your button as below..

 

 

 Behavior = Execute Javascript

Content Source = Onclick Javascript

 

Select Field Type:

 

code in below text area..

 

var currurl = window.location.href;
var lastid = currurl.split('/');
if('{!Your_checkbox_field__c}' == false){
  window.location = '/apex/yourpagename?id='+lastid[3];
}else{
  alert('You can\'t able to create new');
}

 


Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

RobotiRoboti
Thanks Hitesh,

We added the code and tested. Initially the checkbox field is unchecked (FALSE) but everytime we click on the button, we get the message - "You can't able to create new".

Then we update the checkbox field to TRUE, and click on the button again. We get the same message.

Also, we should be able to update the checkbox field to TRUE after the first click of the button.

It is too much asking, but you can help.

Thanks again!
RobotiRoboti
In both the cases (TRUE or FALSE) it is showing the Alert.
hitesh90hitesh90

Hi,

 

sorry for late reply.

 

Try to use "0" instead of "false".

 

code in below text area..

 

var currurl = window.location.href;
var lastid = currurl.split('/');
if('{!Your_checkbox_field__c}' == 0){
  window.location = '/apex/yourpagename?id='+lastid[3];
}else{
  alert('You can\'t able to create new');
}

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

RobotiRoboti

Hi Hitesh,

 

Yes we got it by using "0" instead of "false".

We have removed following line from the code - 

var lastid = currurl.split('/');

...because we have given the URL of an external system.

The if statement is working perfectly. Thanks!

 

But, we want to update our checkbox field to "1" (checked) as soon as the if statement finds that it is "0". We are not able to update it. We are writing this code - 

 

var currurl = window.location.href;
if('{!Your_checkbox_field__c}' == 0){

  '{!Your_checkbox_field__c}' == 1
  window.location = '/apex/yourpagename?id='+lastid[3];
}else{
  alert('You can\'t able to create new');
}

 

We don't know where it is getting wrong. It is performing the if statement correctly but it is not updating the checkbox field value to "1" (checked).

 

Thanks in advance!

 

 

 

hitesh90hitesh90

we can't update checkbox field value from here. it's not possible.

for updating field value you have to use Apex class (controller) or Apex Trigger.