6

I came across something weird, SOQL which has a filter as cross-Object picklist field doesn't return rows, even if records exist.

Minimum viable code to replicate:

  1. Create a new custom metadata type, Name it as 'Parent'
  2. Create a picklist filed on it, name it as 'Type__C' and provide 2 value choices for it namely 'Option1' and 'Option2'
  3. Create a new record for Parent, name it as 'Dad' and chose 'Type__c' as 'Option1'
  4. Create a new custom metadata type , Name it as 'Child'
  5. On child, create a new custom metadata relationship field name it as 'Parent__c'
  6. Create a new record of Child and select parent as 'Dad' record (As in step 3)
  7. Now run this SOQl

    SELECT DeveloperName,Id,Parent__r.Type__c FROM Child__mdt where Parent__r.Type__c='Option1'

It will return zero rows, even if It has records that meet these criteria.

Converting that field (Type__c) from Picklist to free-text makes it work, but then I cannot use the restricted picklist feature and it is now more prone to errors.

I cannot use, validation rule as well because it has 20+ values so it will be overhead to do.

Does anyone know about this bug? I couldn't find it on known issue as well. Is there any workaround for this?

Edit: If I direct query parent object with the same filter, it works. :(

Edit (18/12/2018) : After days of back and forth, they have recognized this as a bug (W-5709686 ), and there is No ETA for the fix.

3
  • Is it normal picklist, or multivalue? I am thinking about INCLUDE operator in WHERE clause, could that be a point?
    – patryk
    Jun 18, 2018 at 17:47
  • Normal picklist, no multislect Jun 18, 2018 at 17:48
  • As of this writing, the bug is still not fixed. Another confirmation of the issue clarifies that it's an internally-logged bug, thus not on Known Issues site.
    – identigral
    Feb 27, 2020 at 3:57

1 Answer 1

0

The reason of this issue is that query field on parent returns [Object object] which is unable to capture it and equate with String type value(s).

The work-around can be that use inner SOQL from Parent metadata to Child metadata, like

List<Parent__mdt> lstEntitlementMetadata = [SELECT Id, Type__c, 
(SELECT Id FROM Child_relationship_name__r) 
FROM Parent__mdt WHERE Type__c='Option1'];

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.