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
Philip DeGraafPhilip DeGraaf 

Javascript Button to Validated Required fields

I've searched high and low for an example of a Validation button(javascript) for my custom object. What I need the Validate Button to do is to validate what fields should be required based on a picklist selection. I was really hoping not to do any apex. The reason for using the button on the custom object instead of standard required fields is so the Sales reps can save as they go before validating required fields.
Philip DeGraafPhilip DeGraaf
Another thing about my need is the Validation button for reqired fields changes depending on what is selected for picklist value. Example:  selection 1 in the picklist will make 10 fields required but  selection 2 will make 5 fields required.
Philip DeGraafPhilip DeGraaf
This is a Custom Object, not using VF page.
badibadi
Why not use validation rule? 
if(ISPICKVAL(picklist_field, "selection 1"), (validate 10 fields), IF(ISPICKVAL(picklist_field, "selection 2"), validate _5_fields, false))
Philip DeGraafPhilip DeGraaf
still the same issue if it is a validation rule you can't save unless the field is filled in. It has to be a Javascript button, so that the Sales reps can save the Application, the process of filling it out could be days before it is submited to the boarding system. The Javascript validation button looks at the AML Exemeption Class Picklist to know what Identity Proof fields are required. If all fields are filled in then the Sales Application can be submited to boarding system. The only process the button is doing is validating that the required fields are filled in. Below was my attempt and doing this, but it doesn't work correctly.
if( {!NOT(ISPICKVAL(mycustomobject__c.Required__c, 'Business Address Required'))} &&{!ISBLANK(mycustomobject__c.B_Zip_Code__c)}) 

{ 
alert('Please populate Business Address Fields'); 
} 

else if({!NOT(ISPICKVAL(mycustomobject__c.Required__c, 'Federal Tax Address Required'))}&&{!ISBLANK(mycustomobject__c.FT_Zip_Code__c)})

{ 
alert('Please populate Federal Tax Address Fields'); 
}

else if({!NOT(ISPICKVAL(mycustomobject__c.Required__c, 'Mailing Address Required'))}&&{!ISBLANK(mycustomobject__c.Mailing_Zip_Code__c)})

{
alert('Please populate Mailing Address Fields'); 
}

else{ 
alert('Ready to Submit to boarding'); 
}