You need to sign in to do that
Don't have an account?
DennoP
How do I add validation to a custom button
I have added a custom button to a custom object (employee__c). The button takes to user to a visualforce page based on a URL and userid field held in one of the fields on the employee__c record.
I would like to know how I can make sure that if the field is blank the user is not taken anywhere by the custom button, or even better the custom button gives a usefull message e.g. "The user field is blank".
Does anyone have any idea how this sort of valiation can be added on the button.
I started with you example, but had a couple of errors. This amended version (fixed by a friend, not me) seems to work now.
if ({!ISNULL( Employee__c.Salesforce_User__c )}) { alert('The user field is blank!');} else { location.replace('/apex/userupdate?id={!Employee__c.Salesforce_UserId__c}&previd={!Employee__c.Employee_Record_ID__c}');}
Thanks
All Answers
Set the custom button to execute Javascript instead of navigate the page, and then put a JS if statement at the beginning, like
if ('{Employee__c.User__c}'=='') { alert('The user field is blank!'); } else { location.replace('/apex/MyVisualforcePage'); }
I started with you example, but had a couple of errors. This amended version (fixed by a friend, not me) seems to work now.
if ({!ISNULL( Employee__c.Salesforce_User__c )}) { alert('The user field is blank!');} else { location.replace('/apex/userupdate?id={!Employee__c.Salesforce_UserId__c}&previd={!Employee__c.Employee_Record_ID__c}');}
Thanks