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
It'sSaurabhIt'sSaurabh 

I have List of users stored in Custom Metadata, and now i want to check if the running user (Userinfo.getname()) is available in the list that i queried from custom metadata how to achieve this,

I Tried doing in below way, Please help


 List <DET_Allowed_users__mdt> Userlist = [SELECT Id, Users__c FROM DET_Allowed_users__mdt];
List<String> str1 = New list<String>();
   
    for (DET_Allowed_users__mdt Det:Userlist);
      str1.add(Det.Users__c);
    System.debug('see this '+str1);
   
    String str = Userinfo.getname(); 
    if(str1.contains(str) ){
VamsiVamsi
Hi,

Looks like List contains method is case sensitive ... Use the below
 
   List<String> str1 = New list<String>();
   
for (DET_Allowed_users__mdt Det:[SELECT Id, Users__c FROM DET_Allowed_users__mdt])
{
      str1.add(Det.Users__c);
    System.debug('see this '+str1);
}

if(str1.contains(Userinfo.getName().toLowercase()))
{
    system.debug('executed');
}
Please mark as best answer if the above helps...!!!