Ask Search:
Mark Curtis-WoodMark Curtis-Wood 

How do I write a Validation rule for a custom button?

Hi, how do I write a validation rule to make an ACCOUNT field required when clicking a custom button on the ACCOUNT record?
My custom button currently fires of an Adobe Sign agreement. My existing code is;

/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Account.Id}&templateId=a021a00000KmA0h

The field I want it to check is !Account.Masterpack_Acc_No_Networks__c

Thank you in advance
Best Answer chosen by Mark Curtis-Wood
Sathishkumar PeriyasamySathishkumar Periyasamy
You can create Javascript button instead or URL and use below Script
 
{!REQUIRESCRIPT('/soap/ajax/26.0/connection.js')} 
var accReq = "{!Account.Masterpack_Acc_No_Networks__c}";
if(accReq != '') {
window.location="/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Account.Id}&templateId=a021a00000KmA0h";
}
else {
alert('Masterpack_Acc_No_Networks is mandatory');
window.location.reload(); 
}

User-added image

All Answers

Jake BrushaferJake Brushafer
You are going to have to look in your button for it and display a message. https://developer.salesforce.com/forums/?id=906F00000005JoPIAU
Your other option is to create an image formula.  Basically you take a picture of the button and save it as an image. Then make your formula an if statement, look for your value and if it exist display the button with the url tied to it.  This will be a field on the layout as apposed to being in the normal button section. https://help.salesforce.com/articleView?id=useful_advanced_formulas_image_links.htm&language=en_US&type=0
Sathishkumar PeriyasamySathishkumar Periyasamy
You can create Javascript button instead or URL and use below Script
 
{!REQUIRESCRIPT('/soap/ajax/26.0/connection.js')} 
var accReq = "{!Account.Masterpack_Acc_No_Networks__c}";
if(accReq != '') {
window.location="/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Account.Id}&templateId=a021a00000KmA0h";
}
else {
alert('Masterpack_Acc_No_Networks is mandatory');
window.location.reload(); 
}

User-added image
This was selected as the best answer
Neelesh Ratn DwivediNeelesh Ratn Dwivedi
Hey Mark, you have to write java script button to validate on click of a button. You can follow the link shared by jake in hs comment.
Mark Curtis-WoodMark Curtis-Wood
Thanks everyone for your feedback and suggestions. Sathishkumar Periyasamy you are a star, this worked perfectly first time. I really appreciate you taking the time to provide such an easy to follow solution.