+ 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

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

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.