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
Kayla Even 8Kayla Even 8 

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.
Santoshi K VSantoshi K V
Hi Even,

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
Kayla Even 8Kayla Even 8
Hello - I have tried this code and since it is javascript and I am not able to have a javascript button in Lightning, it will not work for me.