0

I have written below code and its causing me the error:

Invalid bind expression type of RecordType for column of type String

Here is the code for reference

Map<Id, RecordType> caseMap = new Map<Id, RecordType>(
    [SELECT Id, DeveloperName
    FROM RecordType 
    WHERE SObjectType ='Case' AND Id='111111']
);
List<RecordType> recordTypes = caseMap.values();    
List<Case_Entitlement_Setting__mdt> EntitlementList = [
    SELECT Id,Record_Type__c,Category__c,Sub_Category__c,Entitlement_Name__c 
    FROM Case_Entitlement_Setting__mdt
    WHERE Category__c='BBB' AND Sub_Category__c='AAA' 
        AND Record_Type__c IN :recordTypes
];

The error coming on below line

AND Record_Type__c IN :recordTypes];
2

You can only use the IN :sObjectCollection syntax when the field you filter on is a lookup. Otherwise, IN can only be used on a collection which matches the field type. For a text field, you need to match on a collection of String.

If you want to filter on the Ids, you can just filter on the keySet:

AND Record_Type__c IN :caseMap.keySet()

If you wanted to filter on, say, DeveloperName, you'd have to build the collection manually:

Set<String> recordTypes = new Set<String>();
for (Recordtype record : caseMap.values())
    recordTypes.add(record.DeveloperName);

... AND Record_Type__c IN :recordTypes

Your Answer

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