You need to sign in to do that
Don't have an account?
Nuno.Carvalho
Button to extend a date
Hi guys,
I need to create a button onclick to update a date field on contracts , all i want to do is to extend the contract 2 years.
I´m new to creating buttons , so if you can explain to me how to do it i would be very appreciated.
Final do Contrato means Contract expiration date.
That´s de field i want to update,
Regards,
Nuno.
I need to create a button onclick to update a date field on contracts , all i want to do is to extend the contract 2 years.
I´m new to creating buttons , so if you can explain to me how to do it i would be very appreciated.
Final do Contrato means Contract expiration date.
That´s de field i want to update,
Regards,
Nuno.
In the Apex Class, you can put the below code - In the Apex class we have created a webservice which accepts the Id of the Contract as parameter and would query for the End Date and Update it after adding 2 years to the current value. If the update was successful and if no errors were encountered, then it would return a True response. Else if any error has occured, it would return a False response and a message stating the error.
Now lets create the button.
Then click on new New Button or Link. Enter the name of the button and select the type as Detail Page Button. And as the behaviour select Execute JavaScript. The Content-Source should have been set to On-Click Javascript automatically. If not, select it.
Now enter the below code in the button - In the JavaScript, we send the Id of the selected Contract to the webservice method which we have defined in the Apex class. If we get a true response, we reload the page and if an error has occured, the error message will be displayed as an alert.
All Answers
In the Apex Class, you can put the below code - In the Apex class we have created a webservice which accepts the Id of the Contract as parameter and would query for the End Date and Update it after adding 2 years to the current value. If the update was successful and if no errors were encountered, then it would return a True response. Else if any error has occured, it would return a False response and a message stating the error.
Now lets create the button.
Then click on new New Button or Link. Enter the name of the button and select the type as Detail Page Button. And as the behaviour select Execute JavaScript. The Content-Source should have been set to On-Click Javascript automatically. If not, select it.
Now enter the below code in the button - In the JavaScript, we send the Id of the selected Contract to the webservice method which we have defined in the Apex class. If we get a true response, we reload the page and if an error has occured, the error message will be displayed as an alert.
Thank you very much, you helped a lot, not only with the code but understanding it,
Best Regards,
Nuno.