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
jldenningjldenning 

Validation Rule Comparing 2 Ids

Is it not possible to compare 2 Id values using basic == <> operators in a validation rule?


The background.....

 

We have a custom object with lookups on both a Lead and Account so that the user may use it for either one.  

We also have a trigger that when the lead is converted to an account, the convertedAccountId value is copied into the Account field of the custom object.

 

I am trying to create a validation rule that if both the lead and account fields are populated for the custom object, the Account Id must match the convertedAccountId from the lead. The rule below evaluates to true when trying to convert a Lead and prevents the Lead from being converted.  When I turn the rule off the conversion works fine and manual comparison of the ConvertedAccountId and Account__c shows they are the same.  

 

 

AND(NOT(ISBLANK(Lead__c )),

 NOT(ISBLANK(Account__c )),   

 Lead__r.ConvertedAccountId  <>  Account__c  )

Ispita_NavatarIspita_Navatar

I think the issue you are facing is due to the 18 digit and 15 digit id of the same object. In the SOQL the 18 digit and 15 digit ids of the same object are evaluated as same , but I think in the same of validation rule the  same thing does not apply , you can probably move the logic to trigger, then the problem should be eliminated.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

 

 

 

 

 

jldenningjldenning

It needs to be in a validation rule so users don't mistakenly enter a lead and an account that's not the same as the convertedAccountId because we wouldn't be able to tell which object the custom object should actually refer to.  When done from the trigger it should always be the same and the rule wouldn't be needed, but the validation still checks.  

 

Is there anywhere in the logs to see what is actually being compared or to output the 2 Ids in the error message of the validation rule?