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
SjaleelSjaleel 

Condtional Button

Dear Developers,

 

Is there a way to make a button conditional, that is the button command would be only executable depending on the value of a certain field in the object.

 

For eg.

 

If the status in the page is approved , the button would be excutable that would deirect to an email page that is.

 

Can anyone help me on this?

 

Regards and thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

Problem must be here :

 

 

if('{!CustomObject.status}'.toLowerCase() == 'Approved'.toLowerCase())
{
    alert('Hi');
    window.location.href = '/apex/MaintenanceReserveInvoice?id={!CustomObject.Id}' ;
}

 

 

Conditions must not be matching...So alert will help you to know that code in coming in if condition or not..Also use toLowerCase and match the conditions.

 

 

Thanks
Ankit Arora

 

All Answers

kiranmutturukiranmutturu

you can do like this

 

 

<apex:commandButton value="Delete"   disabled="{!if((status == 'approved') ,'false','true')}" action="{!DeleteShipDetail}" immediate="true" id="btndel" rerender="ShipmentDetailList" status="deleteStatus"  >

 

 

u can disable the button like above or u can hide the button by using the style property...

SjaleelSjaleel

its not a comman button in VF page, but a custom button on the objects page.

 

Thanks and regards

Ankit AroraAnkit Arora

You can do something like this :

 

<apex:commandButton value="SendMail" rendered="{!if((status == 'approved') ,true,false)}" action="{!YourEmailRedirectMethod}" >

 

 

Thanks
Ankit Arora

 

Ankit AroraAnkit Arora

Sorry we posted at the same time so was not able to see your latest comment. Now to disable the button : I don't think so we can do this. But somehow possible if you can create a hompagecomponent which will run a script which in end will hide the button.

 

Or you can write a JS on your custom button on object which will give a error alert if your conditions are not fulfilled.

 

 

Thanks
Ankit Arora

 

Imran MohammedImran Mohammed

Add if condition in the custom button javascript code.

For ex: 

if('{!CustomObject.status}' == 'Approved')

{

//add the functionality that should execute if the above condition is true

}

 

Let me know if it did not work.

SjaleelSjaleel

it didnt work

 

it gives an error " A problem with the Onclick Java Scrpt for this button was encountered Unexpected token }

 

if('{!CustomObject.status}' == 'Approved')

{

    /apex/MaintenanceReserveInvoice?id={!CustomObject.Id}

}

 

Thanks anr regards

Ankit AroraAnkit Arora

Try this :

if('{!CustomObject.status}' == 'Approved')
{
    window.location.href = '/apex/MaintenanceReserveInvoice?id={!CustomObject.Id}' ;
}

 

Thanks
Ankit Arora

 

 

SjaleelSjaleel

The button is not working, no error messages neither any results!

 

Thanks and Regards

Ankit AroraAnkit Arora

Problem must be here :

 

 

if('{!CustomObject.status}'.toLowerCase() == 'Approved'.toLowerCase())
{
    alert('Hi');
    window.location.href = '/apex/MaintenanceReserveInvoice?id={!CustomObject.Id}' ;
}

 

 

Conditions must not be matching...So alert will help you to know that code in coming in if condition or not..Also use toLowerCase and match the conditions.

 

 

Thanks
Ankit Arora

 

This was selected as the best answer
SjaleelSjaleel

Thanks alot worked like a charm

 

^__^

 

Regards

SAj