
I have a Javascript button (obviously Classic) and a Validation Rule. The Validation does work when the button is clicked and the criteria are met. However, it does not display the error message...
This is the button script;
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var Demo = new sforce.SObject('Demo__c');
Demo.Id = "{!Demo__c.Id}";
Demo.Status__c = "Completed";
sforce.connection.update([Demo]);
document.location.reload(true)
and the error message should be...
Please add Demo Contacts before marking this demo as complete.
How do I display the error message? Thank you.
답변 2개
Try this code:
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var Demo = new sforce.SObject('Demo__c');
Demo.Id = "{!Demo__c.Id}";
Demo.Status__c = "Completed";
var result = sforce.connection.update([Demo]);
if(result[0].success=='true'){
location.reload();
}
else{
alert('Update Failed:' + result[0].errors.message);
}