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
Edgar MacachorEdgar Macachor 

What is wrong with my validation rule formula?

HI guys help!! I have to create a validation rule that the Contact Lookup should be under the same Account and now I have created a formula but I think it doesn't work right.
So here's my code:
AND( CreatedBy.Contact.AccountId = Contact__c,
     Account__r.Id  = Account__c,
     Account__r.Id <> CreatedBy.Contact.AccountId)


Can you help me find what is wrong about my formula.
Best Answer chosen by Edgar Macachor
CharuDuttCharuDutt
Hii Edgar
Just Copy Paste Below Code In Validation Rule
Account__r.Id <> Contact__r.AccountId
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Edgar Macachor
Try Below Validation
EXAMPLE
AccountId  = Account Lookup In Order Object
CustomerAuthorizedBy.AccountId = Contact lookup In Order Object CustomerAuthorizedBy Is Field Name
AccountId <> CustomerAuthorizedBy.AccountId
Please Mark It As Best Answer If It Helps
Thank You!

 
Edgar MacachorEdgar Macachor
Hi CharuDutt! I appreciate your answer. I tried the code you suggested, this is it:
AccountId  = Account__c 
CustomerAuthorizedBy.AccountId = Contact__c 
AccountId <> CustomerAuthorizedBy.AccountId

But after I check syntax it an error showed: Error: Syntax error. Extra CustomerAuthorizedBy.AccountId.
Do I have to create a field named CustomerAuthorizedBy?
CharuDuttCharuDutt
Hii Edgar
In Which Object You Want To Make
Edgar MacachorEdgar Macachor
Hi CharuDutt, Yes I'm creating this validation rule on my Custom Object named: Order
 
CharuDuttCharuDutt
Can You Give The Account And Contact Lookup Field Names
Edgar MacachorEdgar Macachor
Account is Account__c
Contact is Contact__c
 
CharuDuttCharuDutt
Hii Edgar
Just Copy Paste Below Code In Validation Rule
Account__r.Id <> Contact__r.AccountId
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer
Edgar MacachorEdgar Macachor
Wow!! Thank you so much CharuDutt, that solved my problem.