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
Alexander G GoodmanAlexander G Goodman 

Conditional validation using Visualforce

I am try to make a vaildation rule that kicks in on the Opportunity object, if a field in Opportunity Product object meets certain critia. The field is a date field. Firstly is this possable with Visualforce? and if so how as I have no experience with Visualforce.
Abhi_TripathiAbhi_Tripathi
you can create validation rule on Opportunity

Go to Your name => Setup => Customize => Opportunity => Validation Rules
For more details you go to the below link
http://help.salesforce.com/apex/HTViewHelpDoc?id=fields_defining_field_validation_rules.htm
 
Alexander G GoodmanAlexander G Goodman
I have tried that, it does not work. I can't get into the Opportunity Product from the Opportunity Object which it a 1 to many relationship. as I need to pull a custom Date Field from Opportunity Products.
So my question is can I create a Cross object validation rule with a 1 to many lookup relationship (which will trigger on the opportunities object based on critia in the Opportunity Products Object) using either Date Field or Text Field were the rule kickes in this the field is blank?
Abhi_TripathiAbhi_Tripathi
First of all, you cannot show validation error on saved records that you have asking.

Secondly If you have a page where user is trying to insert Opportunity as well as Opportunity products both at the same time (that is possible only using vf page) then only you can show validation error.
Validation you can check in the controller of the page.

Let me know for further queries
Alexander G GoodmanAlexander G Goodman
I don't think were on the same page, What i am trying to do in the simplest way is create a Validation rule thar triggers on critia in a related object.
So when a date field is empty in Opportunity Products it stops the related opportunity from closing and I can't make the field in Opportunity Products required.
Abhi_TripathiAbhi_Tripathi
For your scenario you can write a trigger on Opportunity that will check the date field on the Opportunity Product and then will restrict the user from closing the Opportunity. 
You can do this using trigger only. let me know if this helps
Alexander G GoodmanAlexander G Goodman
That does help even though the opportunity can have more then one product on it, I just have no clue how to write and implement it.