[SalesForce] How to fetch Custom Metadata Type record in apex and compare it with a string

I have a string which is holding email ids of users from my org.
Now I have few custom metadata type records which are holding email IDs of users who are inactive.

Now I need to compare the string which has all my users' email IDs with that of custom metadata type Email field.

It is like

If(allEmailIds == Inactive_Email__c){ //allEmailIds is the string holding my org users' email ids
//do the logic here;
} 

I knew the query to fetch custom metadatatype records into apex but I'm not getting the logic to compare these two values.
Below is the query of my custom metadata type object

Select MasterLabel, Inactive_Email__c from InactiveUsers__mdt

Can anyone please help me out with this requirement.

Best Answer

As comments suggests there might be some better solutions to get or store InActive Users information rather than using Custom Metadata Type records for it.

But to your question - Sounds like you are trying to get a field value (Inactive_Email__c) from a Custom Metadata Type records stored on InactiveUsers__mdt and then compare it with a different string value received as Input or from a different Query.

Below Example can show a way to achieve this...

InactiveUsers__mdt[] InActiveEmailRecords = [Select MasterLabel, 
Inactive_Email__c from InactiveUsers__mdt];
  Set<String> InActiveEmails = new Set<String>();
  for(InactiveUsers__mdt record:InActiveEmailRecords) {
      InActiveEmails.add(record.Inactive_Email__c);
  }
  //Example Query for User based on the InActive Email addresses in mdt
  User[] InActiveUsers = [Select Id,Name,Email From User WHERE IsActive=false AND Email IN:InActiveEmails ];

 // OR If you want to match with a certain string
 for(String email:InActiveEmails) {
      if(email == "YourString"){
          // Your logic goes here...
      }
  }