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
ArunForceArunForce 

Validation rules-comparing the field from one custom object with another custom object field

Hi all,

I am having two custom objects which is named as custom_object1__c,custom_object2__c.Now i want to write the validation rule on custom_object1__c saying that "custom_object1__c.transactiondate  should be always greater than custom_object2__c.somedate".

 

I have written the validation rule like this.

transactiondate__c < custom_object2__c.somedate__c

 

I am getting the following error.

Error: Syntax error. Found 'custom_object2__c'

 

how can i write the rule for this scenario.

please help me to solve this.

 

thanks,

Arun.

Best Answer chosen by Admin (Salesforce Developers) 
Grazitti InteractiveGrazitti Interactive

Hi Arun,

 

To access the information of Object2 in validation rule on one object1, there must be relation like Lookup or Master-Detail between objects. If there is not any relation then use trigger on Object 1 but also make sure that there should be one field on both object that corresponds both object records.

 

Let me know if you require trigger.

 

Thanks

www.grazitti.com

All Answers

Grazitti InteractiveGrazitti Interactive

Hi,

 

I think there is Lookup or Master-Detail Relationship between Object 1 and Object2. If yes then access corresponding field of Parent Object by relationship name as following.

 

transactiondate__c custom_object2__r.somedate__c

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

 

Thanks

www.Grazitti.com

ArunForceArunForce

hi Grazitti,
thanks for your quick reply.I dont have lookup or masterchild relationship between these two objects.Is it possible still?

thanks,
Arun.

Grazitti InteractiveGrazitti Interactive

Hi Arun,

 

To access the information of Object2 in validation rule on one object1, there must be relation like Lookup or Master-Detail between objects. If there is not any relation then use trigger on Object 1 but also make sure that there should be one field on both object that corresponds both object records.

 

Let me know if you require trigger.

 

Thanks

www.grazitti.com

This was selected as the best answer
ArunForceArunForce

hi Grazitti,

thanks for your explaination.I will go for triggers.