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

Display confirm message while clicking a custom button.

Hi All,

I have a custom button and whose content source is a visual force page. The visualforce page is like below:

<apex:page standardController="obj__Billing_Event__c" extensions="ReleaseBEController" recordSetVar="bes" action="{!releaseBEs}"> </apex:page>

So, the page directly calls "releaseBEs" method and it does the required operation. This button is there in list view page of the Object and another button is there with exactly same functionlity and that's used in deatils page.

Using the two button user can perform some operation.

What I want is to display a confirm message if certain condition satisfies. Example: One of the field in selected record is null. If user wants to process the operation then needs to clcik on OK and if user clicks on cancel then the process will stop there. If the selected data is correct then don't neeed to display any message.

There are many examples related to this but all are using "commandbutton". This is not possible for me to change that.
Medhya MahajanMedhya Mahajan

You can use a javascript button instead of a Visualforce button.

Apply if else to check for the condition and based on the user's response redirect him to the URL of the VF ( for OK )  or redirect back to same page ( for cancel ).

Let me know if this helps.

Medhya Mahajan
Hi Medhya,

If I will modify that in JS then how I'll validate a field for all selected records? Actually I was thinking if we can write this validation logic in the controller and from there we can send the message to the UI to display the warning message.

Medhya MahajanMedhya Mahajan

What I suggested can be done with a detail page button ( I asumed, since you mentioned that also in the description).

To validate your field for selected records ( on list view page )  you have will have to get all the selected records in your controller of the page ( mentioned above) then check their field and based on that you can set some variable.

Now you can use this variable in the JS that you insert in this VF for which you have created button.

Medhya Mahajan