function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Wael RAWAS 7Wael RAWAS 7 

How can i create a custom button that lunches the validation rules in a page?

Hey everyone,
I have records in a custom object, and validation rules are created after the records were integrated. So, the records before adding the validation rules are not validated. 

That's why i need to add a custom button that can validate the record, which means call the validation rules function to verify that the records' contents are valid. How can i do this ? can i trigger the validation rules? can lunch the save button ? 

Ps: i don't want to rewrite all the validation rules in code

Thank you in advance

Amit Chaudhary 8Amit Chaudhary 8
You can use the java script for same like below post:-
https://success.salesforce.com/answers?id=90630000000gwO5AAI
Example 1:-
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

//Grab the status value you're interested in, and I'm blanking on how to do this at the moment

if(status <> "Particular Value"){
alert("Nice try, think again.");
}
else{
window.open('/apex/<whatever your page is>');
}


Example 2: - https://success.salesforce.com/answers?id=90630000000CjubAAC
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}

if("{!Contact.New_Hire_Start_Date__c}" !== ""){
    var contactToUpdate = new sforce.SObject("Contact");

    contactToUpdate.Id = "{!Contact.Id}";
    contactToUpdate.Recruiting_Status__c = "NURF Initiated";
    contactToUpdate.Workflow_Trigger_FOR_NURF__c = "1";

    var result = sforce.connection.update([contactToUpdate]);

    if (result[0].success === "false"){
        alert(result[0].errors.message);
    }
    else{
        location.reload(true);
    }
}
else{
    alert("The New Hire Start Date field has to be checked!");
}

Example 3:- PLease check below post for step by step process
http://salesforce.stackexchange.com/questions/8521/how-to-build-a-salesforce-custom-button-with-validation-rules

http://salesforce.stackexchange.com/questions/4497/button-validation-logic

Please let us know if this will help you,

Thanks,
Amit Chaudhary
Wael RAWAS 7Wael RAWAS 7
Thank you Amit,
But as i indicated, i don't want to rewrite my validation rules in the javascript. I'm looking for triggerubg the validation rule instead of rewriting hundreds of validation rules in form of code.