Advertisement
martyychang

Account Custom Button: Validate

Jan 31st, 2014
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Establish a connection to the API,
  2. // using the current session ID
  3.  
  4. {!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
  5. sforce.connection.sessionId = "{!$Api.Session_ID}";
  6.  
  7. // This button was created to attempt validation of an Account.
  8. // All we have to do is instantiate the account in JavaScript,
  9. // and set the IsValidating__c field to true, which we assume
  10. // will set off the desired validation rule
  11.  
  12. var account = new sforce.SObject("Account");
  13. account.Id = "{!Account.Id}";
  14. account.IsValidating__c = true;
  15.  
  16. // Attempt to update the account record.
  17. // This requires the account to be placed in an array, and
  18. // the update results will similarly be given back in an array
  19.  
  20. var results = sforce.connection.update([account]);
  21.  
  22. // Examine the results to see whether our update was successful.
  23. // If it was, then all is well. We will assume there is an associated
  24. // workflow rule that will clear the IsValidating__c checkbox.
  25.  
  26. if (results[0].getBoolean("success")) {
  27.     alert("Validation succeeded!");
  28. }
  29. else {
  30.     alert("Validation failed...");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement