6

I encountered the strangest error today, and I wanted to make sure that this is a real thing and not just a silly mistake of mine.

I had a validation rule on Lead:

And( 
  isblank(Address), 
  $RecordType.Name = "Internal Leads" 
)

When creating a Lead object with only the State part of the address populated in a test class, I got the following error:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Validation Formula "Validate_Address" Invalid (Programmer Error: Can't get an enum with a fieldId for a compound field): []

I'm completely aware of how to fix the problem, just split the Address field into its parts. But I want to make sure I am right in interpreting what just happened. Is this in fact a runtime error when evaluating a validation rule?

There is a trigger on lead which requires has some dynamic logic that references the schema, so it may explain the direction the error took, but it doesn't explain why it happened.

  • I am getting the same error and to make matters worse - it is only breaking in production when an unit test is trying to setup test data :D – dzh May 21 '17 at 2:46
  • 1
    Thanks for posting this, @SFDC Neuf. Just had the same question and Google brought be here :) Long time no see – Brent Bow Dec 18 '17 at 23:23
4

Address is a compound field that can only be accessed either from SOAP or REST API.

If you want to verify the Address attributes, you need to verify individual field components of Address Compound field.

Refer Compound Field Considerations and Limitations

Also refer, restrictions in Validation Rules(documentation):

  • Compound fields, including addresses, first and last names, and dependent picklists and lookups
  • Campaign statistic fields, including statistics for individual campaigns and campaign hierarchies
  • Merge fields for auto-number or compound address fields such as Mailing Address
  • I confirmed that the doc does say exactly what Santanu wrote above. What is amazingly strange is that for me the validation rule formula works fine in one Developer sandbox but not in a different Full sandbox. In the Full sandbox I get the same error reported in the question, "Programmer Error: Can't get an enum with a fieldId for a compound field". – Marty C. Jan 25 '18 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.