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
Prafulla PatilPrafulla Patil 

Is it possible to do ajax form validations in salesforce ?

I want to do ajax validation in salesforce standard page.


Example - on Edit Contact Page there is field 'Phone' i want to validate this field when focus moves out from this perticular field. We dont want user to click on Save button and then show validation message, when user moves from Phone field to other field it should validate at the point of time.


Salesforce native functionality doesn't operate that way, nor offer the ability to add a dynamic validation.  You have to try to save the record, and then the validation rules fire.


However, you can certainly write your own VisualForce page which can do this.  Use <apex:inputField> tags for the fields, and then use standard javascript to bind whatever functions you want.  Investigate jQuery if you don't use it already.


However... consider that it's not the "Salesforce way".   You lose the benefits of Salesforce validations (or you double validate which could have it's own problems.)  Your pages will operate differently than all the other pages the user comes across unless you re-write them all.  One might argue that it's better to be consistent and just leverage the capabilities that the platform offers.    Id' think it has to be a *very* compelling business case before going down that road. 


Best, Steve.

Prafulla PatilPrafulla Patil

Thanks for your reply,

I was aware that I can do it through custom VF page, but will not work in my case as client needs that for all forms in application 


what we needed and asked above is very basic functionality required now days .... and I have seen lots of other platforms supporting that .. anyways salesforce should add it.

I will try to post same in IdeaExchange


Sometimes it's good to push back on a client when they are asking for something that the platform *they chose* can't easily give them a feature they want.   It reminds them that, hopefully, they made the choice for more strategic reasons than whether validation is onBlur or on Save, and it encourages them to work with the platform they actually bought as opposed to the platform they want.   But then again, sometimes it's just a pain.  :-)   Best, Steve.

Prafulla PatilPrafulla Patil

Very much true about we should push back to client on this, But what are your thought about getting this included in platform ? just asking .


Well, as you say, dynamic validation has been around for ages.  So, not having done it by now can't be by oversight, or because they haven't gotten around to it, it's an intentional choice that's been made.   So, I suspect that it's a done deal and if you really want it, you can do it yourself.  


Before I'd post a new Idea, I'd search for an existing one about Dynamic Validation, and I'll bet it's already there.


Best, Steve.


can we do validations without using JavaScript

Prafulla PatilPrafulla Patil

I am asking about dynamic validations, can you suugest your apporch please


The easiest unsupported method would be to load jQuery into Salesforce, and place a custom Home Page Component on the sidebar that can achieve Ajax validation. You can easily perform real-time validation using this method.


You can determine the object you're editing by checking:




And you can determine if you are on edit mode by checking:





Of course, this could break with any given release, so you might need to test your code before each update, but as of now, this is probably the best way to go about it. You'll want to upload jQuery as a Static Resource; you can reference it in your HTML component as "/resource/jQuery" (assuming you named the resource "jQuery").