I am trying to achieve the following functionality: I have created a metadata configuration that will hold the value and I have built a dynamic query where I will get all the fields added to the metadata. What I am trying is need to compare the metadata values with the record which got through the query.
string query;
set<string> setfieldapinames = new set<string>();
list<string> lstfieldapinames;
list<string> lstvalues = new list<string>();
List<String> collAPIFieldNames = new List <String> ();
list<Metadata__mdt> lstMetadatamdt =[SELECT Id,MasterLabel,FieldName__c,LableName__c,Value__c FROM Metadata__mdt];
if(lstMetadatamdt.size()>0){
for(Metadata__mdt meta : lstMetadatamdt){
lstfieldapinames = meta.FieldName__c.trim().split(',');
setfieldapinames.addall(lstfieldapinames);
if(meta.Value__c!=null && meta.Value__c!=''){
lstvalues.add(meta.Value__c);
}
}
system.debug('lstfieldapinames: '+lstfieldapinames);
system.debug('setfieldapinames: '+setfieldapinames);
query = 'SELECT Id'+','+String.join(new List<String>(setfieldapinames), ',')+' FROM customobject__c';
System.debug('Query ' + query);
List<customobject__c> customobjectquery = Database.query(query);
System.debug('customobjectquery ' + customobjectquery);
Map<String, Metadata__mdt> mapmetadata = Metadata__mdt.getAll();
if(!customobjectquery.IsEmpty()){
for(customobject__c col : customobjectquery){
for(String keySetString : mapmetadata.keySet()){
//--------------I got stuck here while comparing---------------------
if(setfieldapinames.contains(mapmetadata.get(keySetString).FieldName__c)
&& !lstvalues.contains('false') && lstvalues.contains('false')){
System.debug('----->'+mapmetadata.get(keySetString).FieldName__c);
}
}
}
}
}
any help will be appreciated.
Thanks.