You need to sign in to do that
Don't have an account?
Nathan Hahn
Have Custom button Show Validation Rule
Hello,
have a custom object called Bookings in our org.
This is fed off the opportunities and we have a current custom button that is called "modify order".
This button triggers a workflow email as well another workflow to check modify order as true.
Because we have a javascript code that pops up a window, it is not showing any validation rule even though I put this logic check below
Underlined
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
try {
// identify the record
var o = new sforce.SObject("Booking__c");
o.id = "{!Booking__c.Id}";
// make the field change
o.Modify_Order__c= "TRUE";
// save the change
var resulto = sforce.connection.update([o]);
if(resulto[0].success=='true'){
alert('Your Order has been Submitted for Modification');
location.reload();
}
else {
var errors = resulto[0].errors;
var errorMessages = "An error has occurred, please contact your Salesforce Administrator";
for ( var i = 0; i < errors.length; i++ ) {
errorMessages += errors[i].message + '\n';
}
alert( errorMessages ); // display all validation errors
}
} catch ( ex ) {
alert( ex ); // display any javascript exception message
}
have a custom object called Bookings in our org.
This is fed off the opportunities and we have a current custom button that is called "modify order".
This button triggers a workflow email as well another workflow to check modify order as true.
Because we have a javascript code that pops up a window, it is not showing any validation rule even though I put this logic check below
Underlined
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
try {
// identify the record
var o = new sforce.SObject("Booking__c");
o.id = "{!Booking__c.Id}";
// make the field change
o.Modify_Order__c= "TRUE";
// save the change
var resulto = sforce.connection.update([o]);
if(resulto[0].success=='true'){
alert('Your Order has been Submitted for Modification');
location.reload();
}
else {
var errors = resulto[0].errors;
var errorMessages = "An error has occurred, please contact your Salesforce Administrator";
for ( var i = 0; i < errors.length; i++ ) {
errorMessages += errors[i].message + '\n';
}
alert( errorMessages ); // display all validation errors
}
} catch ( ex ) {
alert( ex ); // display any javascript exception message
}
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_javascript_remoting.htm?search_text=javascript%20remoting
Validation rule messages will not be shown on Javascript alert.Instead you can try implenting using a VF page.Please take care of the security when you implement a blank VF page from button -
https://developer.salesforce.com/page/Secure_Coding_Cross_Site_Request_Forgery
Otherwise if you don't have a huge list of validation rules, you can implement them using jvascript in the button itself.
regards,
Shashi
You can display validation error in javasript by using below one liner code.
You can put this code to your else block.
Let me know if it does not work.