You need to sign in to do that
Don't have an account?
Button to Trigger 1 year add to date field
I would like to create a button on our Contract object that will add 1 year to our Contract End Date field and populate it in field End Date Override. I have never worked with apex and javascript is not supported in lightning so I am hoping someone can help me to come up with the proper way to do this.
Please try the below code
{!requireScript("/soap/ajax/37.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Invoice_Statement__c");
c.id ="{!Invoice_Statement__c.Id}";
c.Contract_Date__c = new Date(" {!YEAR(Invoice_Statement__c.Contract_Date__c) + 1}, {!MONTH(Invoice_Statement__c.Contract_Date__c)}, {!DAY(Invoice_Statement__c.Contract_Date__c)}"); newRecords.push(c); result = sforce.connection.update(newRecords); window.location.reload();
or check the below link
https://salesforce.stackexchange.com/questions/127758/adding-one-year-to-date-field-value-through-custom-button
I hope it will be useful for you.
If yes please mark my answer as the best answer.
Thank you