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
TanayTanay 

Help in Date Validation

I have two Object Project & Milestone in M-D relationship. Project  object has Project_Start_Date__c and Project_End_Date__c   &In  Milestone Object has Milestone_Start_Date__c & Milestone_End_Date__c.

 

Now , I want  a validation rule , Where Milestone_Start_Date__c & MileStone_End_Date__c  value should be always In Between Project start & End date.


I Try the code below , But didn't work.:(

 

 

Milestone_Start_Date__c  >=   Project__r.Project_Start_Date__c   &&   Milestone_End_Date__c  <=  Project__r.Project_End_Date__c 

 

 

 

Thanks In advance!! :-)

Best Answer chosen by Admin (Salesforce Developers) 
phiberoptikphiberoptik

Ok, let me step back and think of this big picture...

 

If I am understanding correct, you need an error to be thrown if EITHER the Milestone Start Date or Milestone End Date is equal to or outside of the corresponding Project Start or End Date, right? So the following scenarios would require an error message:

 

MSD is before PSD, but MED is betweenPSD and PED

MSD is between PED and  PSD, but MED is after PED\

MSD is before PSD and MED is afterPED

 

NO ERROR if:

MSD is after PSD and MED is before PED

 

Is this correct?

 

 

Also, do you need to make sure that End Dates are not before Start Dates? I will assume yes. Here you go:

 

OR( 
   Project__r.Start_Date__c >= Milestone_Start_Date__c , 
   Project__r.End_Date__c <= Milestone_End_Date__c,
   Milestone_Start_Date__c > Milestone_End_Date__c 
)

 

All Answers

phiberoptikphiberoptik

What do you mean it didnt work? Did you get a syntax error or did it save successfully but not throw an error when tested?

 

EDIT: Which object did you create the validation rule on?

TanayTanay

Thanks for your reply.

 

I create this validation rule  on Milestone Object .  I didn't get any Syntax error while I saved it even don't get any type of   error .   It's Still not working.

 

please help me out.

 

phiberoptikphiberoptik

What date values are you using to test the rule? What are:

 

Project Start Date

Project End Date

Milestone Start Date

Milestone End Date

TanayTanay

 

 

Below Link is  the snapshot of  project record Details view & corrosponding Milestone record in related list. If you don't mind Can you please go through it.

 

https://picasaweb.google.com/100070508323088817118/November212012#5813150781845174130

 

And this is the snapshot of Validation Rule on Milestone Object.

 

https://picasaweb.google.com/100070508323088817118/November21201202#5813150886755340578

 

Thank you so much for your reply.

phiberoptikphiberoptik

Ok, let me step back and think of this big picture...

 

If I am understanding correct, you need an error to be thrown if EITHER the Milestone Start Date or Milestone End Date is equal to or outside of the corresponding Project Start or End Date, right? So the following scenarios would require an error message:

 

MSD is before PSD, but MED is betweenPSD and PED

MSD is between PED and  PSD, but MED is after PED\

MSD is before PSD and MED is afterPED

 

NO ERROR if:

MSD is after PSD and MED is before PED

 

Is this correct?

 

 

Also, do you need to make sure that End Dates are not before Start Dates? I will assume yes. Here you go:

 

OR( 
   Project__r.Start_Date__c >= Milestone_Start_Date__c , 
   Project__r.End_Date__c <= Milestone_End_Date__c,
   Milestone_Start_Date__c > Milestone_End_Date__c 
)

 

This was selected as the best answer
TanayTanay

Thanks man !! hope In future ,i will get that kind of  help as now. :-)

phiberoptikphiberoptik

Happy to help! Cheers Tanay!