I am completely new to Apex programming and I don't know how to efficiently get values from the Map key. below is the example I need to check three different keys and based on the matching it should return the records. So I have created three new instances for Map to achieve this and if I want another check another set of the key then I need to create another instance which is not the best way of programming? please help me to overcome this issue?
List<Company__c> CompanyList = [select id,Name,Size__c,from Company__c where id in:ProjectId];
List<Opportunity> Opportunity = [Select id,Name,Size from Opportunity];
map<string,Company__c> setOrdKey = new map<string,Company__c>();
map<string,Company__c> setOrdSize = new map<string,Company__c>();
map<string,Company__c> setOrdSize = new map<string,Company__c>();
for(Company__c track :CompanyList)
{
if(track.Name!= null)
{
setOrdKey.put(track.Id,track);
setOrdSize.put(track.Size__c,track);
setOrdName.put(track.Name,track);
}
}
for(integer i = 0; i < Opportunity.size(); i++)
{
if(setOrdKey.containskey(Opportunity[i].Id) && setOrdSize.containskey(Opportunity[i].Size__c))
{
System.debug('Size');
}
else if(setOrdKey.containskey(Opportunity[i].Name)
{
System.debug('Company');
}
}