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
tklinetkline 

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

 

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

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

alert(strResult);
window.location.reload();

 

Thanks, Sam

Praveen SappatiPraveen Sappati

Hi,

 

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(){
    
        if('{!Lead__c.Lead_Statuss__c}'=='Lead'||'{!Lead__c.Lead_Statuss__c}'=='Submission'||'{!Lead__c.Lead_Statuss__c}'=='stage3'||'{!Lead__c.Lead_Statuss__c}'=='stage4'||'{!Lead__c.Lead_Statuss__c}'=='stage5'||'{!Lead__c.Lead_Statuss__c}'=='stage6')
        {
            hideConvertButton("convertButton");
        }
     }
    function  hideConvertButton(btnName){
    try{
                  var convertButtons = document.getElementsByName("Convert");
                  convertButtons[0].className="btnDisabled";
                  convertButtons[0].disabled=true;
                  convertButtons[1].className="btnDisabled";
                  convertButtons[1].disabled=true;
                  
                }
        catch(e) {
            // var ee = e.message || 0; alert('Error: \n\n'+e+'\n'+ee);
        }
    
   
    }
    </script>
      <apex:form >        
        <apex:Detail subject="{!Lead__c.ID}"  relatedList="true" >            
        </apex:Detail>                   
     </apex:form>
</apex:page>