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
Dennis AntleDennis Antle 

BULK CUSTOM METADATA soql where picklist = value

I have two metadata tables meta1, meta2 that have a Parent-child relationship labeled metarelate.
In meta2 the column Type__c is a Picklist.
Below are 2 different methods for querying the metadata tables.
Query 1
String metatype = 'type1';
for(meta1 m : [SELECT Persona__c, metarelate__r.Name__c   from meta1 
                                                            WHERE metarelate__r.Active__c = true 
                                                            and metarelate__r.Type__c = :metatype]){
       //does not loop through any rows.
}
but If I do this
Query 2
String metatype = 'type1';
for(meta1 m : [SELECT Persona__c, metarelate__r.Name__c, metarelate__r.Type__c   from meta1 
                                                            WHERE metarelate__r.Active__c = true]){ 
       if(m.metarelate__r.Type__c = metatype){
                //does loop through rows that have Type__c = 'type1'.
       }
}
 The query has alot of records, so I want to do it the first way, to save on CPU Time. But it will only work the second way, which eats up CPU Time. Why is it that in Query1 the where Clause on Type__c Column is not working. FYI it's a picklist.
 
IGNACIO SARMIENTO LOSADA1IGNACIO SARMIENTO LOSADA1
Hi Dennis,

I tried your example and it is working the 'Query 1'. Are you sure that if it is going inside the 'if' sentence in the 'Query 2'.
If it is not, check your picklist values in the object edition if exists ' 'type1'. Moreover, check your meta1 records if you have at least one which it is linked with a meta2 record whose type is 'type1'.

Let me know if this helps you.
Thanks
Dennis AntleDennis Antle
Sorry, that don’t help.
I will use my actual soql in Developer Console – This works
User-added image
When I add SFDCObjectType__c to the where clause = ‘PermissionSet’ it fails, even though in the first query, it’s clear that the ‘PermissionSet’ value exists for that field.

FYI :  SFDCObjectType__c is a picklist
User-added image
IGNACIO SARMIENTO LOSADA1IGNACIO SARMIENTO LOSADA1
Hi Dennis,

Add this to your query:
Security_Provisioning_AppLevel__r.SFDCObjectType__c LIKE '%permissionset%'
If this doesn't return any record, the most likely is that it doesn't exists any record this query so you should create it.

Let me know if this solves your issue

Thanks

 
Dennis AntleDennis Antle
Tried that, and did not return any rows.
Records Exist with value 'PermissionSet', you can see them displayed in the first query.
User-added image
IGNACIO SARMIENTO LOSADA1IGNACIO SARMIENTO LOSADA1
Are you sure is returning your first query at least one record whose Security_Provisioning_AppLevel__r.SFDCObjectType__c' field is 'PermissionSet'? In your screenshot I cannot any record with this requirement. Could you send me an screenshot with one of these records? If doesn't appear in the first query then you don't have any record that fulfill this criteria.
Dennis AntleDennis Antle
The image I added in previous post has three records that show value 'PermissionSet'.
IGNACIO SARMIENTO LOSADA1IGNACIO SARMIENTO LOSADA1
It is very weird...if you wanted, you could give me system admin access to your sandbox and I could check it. My email is sarmignaciodevsalesforce@gmail.com
Thanks
Dennis AntleDennis Antle
Sorry, I don't think my company would allow that. 
One thing I just noticed is that the relatationship column has the same name for the 'Related List Label' and the 'Child Relationship Name'.
Would that have anything to do with it? 
IGNACIO SARMIENTO LOSADA1IGNACIO SARMIENTO LOSADA1
You are right. I have replicated the same example and it is not working but these examples are working:
SELECT MasterLabel,SFDCObjectType__c FROM Security_Provisioning_AppLevel__mdt WHERE SFDCObjectType__c LIKE '%permissionset%'
SELECT Id,MasterLabel, Security_Provisioning_AppLevel__r.Active__c FROM Security_Provisioning_UserLevel__mdt WHERE Security_Provisioning_AppLevel__r.Active__c = true
It may be a salesforce bug when you query this particular situation, so you should open a case in Salesforce to they can solve this bug.

Thanks