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

Expire Contract Button

Hey guys-


This is probably a simple solution but I couldn't find the code anywhere (checked the salesforce cookbook and code share).  I'd like to make a button that is displayed on the Contract layout that when clicked changes the status to "Expired".


This would essentially be the same thing as the standard Activate button, only it expires contracts instead.


Any help would be appreciated.  Thanks guys!

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Hello tkline,


This might help you..


Create a Class something like this...


global class ContractStatusupdate{

webService static String updatecontractStatus(Id conid) {

    String results;
    Contract c = [Select Id, Status from Contract where id = :conid limit 1];
    c.Status = 'Expired';
    update c;

    results = 'Status Updated';
    return results;


Then Create a custom button called "Expire" on contracts and choose onclick Javascript... copy paste the following code



var idToUpdate= '{!Contract.Id}';

var strResult = sforce.apex.execute("ContractStatusupdate","updatecontractStatus",{conid:idToUpdate});

//first parameter: Name of class, Second parameter: Method name and third parameter: Parameters of the above class method



Thanks, Sam

Praveen SappatiPraveen Sappati



You want to hide a button when the stage is changed or at particular stage then we have to write a visual force page and override the view page of that object the below code will expalin how to hide the button in the Lead  related list view at particular stage.



<apex:page standardController="Lead__c">
    <script src="/js/functions.js" type="text/javascript"></script> 
    <script type="text/javascript" src="/soap/ajax/16.0/connection.js"></script>    
    <script type="text/javascript" src="/soap/ajax/16.0/ajax.js"></script>   
    <script type="text/javascript">
    window.onload = init; 
    function init(){
    function  hideConvertButton(btnName){
                  var convertButtons = document.getElementsByName("Convert");
        catch(e) {
            // var ee = e.message || 0; alert('Error: \n\n'+e+'\n'+ee);
      <apex:form >        
        <apex:Detail subject="{!Lead__c.ID}"  relatedList="true" >