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
F SmoakF Smoak 

Validation Rule on Saving a Call for particular address combination

I have a validation rule to write on a call object which has a related object Address. The address object has 2 picklist fields--- Address Type, State
The objective is if if state!=PR AND Address Type=POB do not allow to save the call for that address combination BUT if state=PR AND address type=POB allow to save the call for that address combination.

Would be really helpful if anyone could help! Tried innumerable ways but all failing!

Thanks in Advance!
Best Answer chosen by F Smoak
goabhigogoabhigo
If you write the validation rule on Call object it should work. However write the API names, instead of fetching it from the metdata through $ObjectType.
AND( NOT( ISPICKVAL(Address__r.State__c, 'PR') ), ISPICKVAL(Address__r.Address_Type__c, 'POB') ) ---> check for the exact API name. You can navigate from Call > Address > those 2 fields.

Also this will work if there is a lookup to Address in Call object.

All Answers

goabhigogoabhigo
Please do provide the formula/criteria that you tried. This seems easy to do.

I think your validation rule will look like this:
AND( NOT( ISPICKVAL(State__c, 'PR') ), ISPICKVAL(Address_Type__c, 'POB') )

Let me know if this works.

--
Abhilash
F SmoakF Smoak
I used similar kind of rule l;ike you suggested

AND( 
ISPICKVAL( $ObjectType.Address_vod__c.Fields.Address_Type__c , 'POB' ), 
NOT( ISPICKVAL( $ObjectType.Address_vod__c.Fields.State_vod__c , 'PR') )
)
 But I am getting syntax error Error: Incorrect parameter type for function 'ISPICKVAL()'. Expected Picklist, received Object

 I guess this ISPICKVAL would not support on object type.
goabhigogoabhigo
Where are you writing this validation rule? Why you need to use $ObjectType ?
F SmoakF Smoak
This would be on Call Object
Address information is displayed on call object as a Long Text area type field. Address Type and State cannot be fetched from there I believe. So I am navigating from Call-->Address-->fields.
goabhigogoabhigo
If you write the validation rule on Call object it should work. However write the API names, instead of fetching it from the metdata through $ObjectType.
AND( NOT( ISPICKVAL(Address__r.State__c, 'PR') ), ISPICKVAL(Address__r.Address_Type__c, 'POB') ) ---> check for the exact API name. You can navigate from Call > Address > those 2 fields.

Also this will work if there is a lookup to Address in Call object.
This was selected as the best answer
F SmoakF Smoak
Thanks I did try to work using lookup to Address and then the address fields but the validation rule isnt working.

Is there any alternative way to resolve ithis?
F SmoakF Smoak
Abhishek Thanks a ton! I totally ignored the simple logic and took a wrong turn to meta data type by ignoring the fields which had FLS but not visible in page layout. The rule is working absolutely fine!
Appreciate your help!
X x 1X x 1
If it helped why don't you mark it as solution. There are people like us who search the forum and check for posts which are solved.
F SmoakF Smoak
Hi Xx1,

Not aware much about the interface in the forum so I replied over comments,but I have marked it now. 

Thanks 
FSmoak