+ Start a Discussion
SFDC pvSFDC pv 

I have text fied in Case(Parent) object, User will enter the number in the text field. If the number is not exists in CHILD object i should insert the record else i should not insert the record.

Map <List<String>,XXX__c > FFMap = new Map <List<String>,XXX__c> ();
List<Case> Caslist= [SELECT Id,AccountID,Number__c FROM Case  WHERE ID =:CaseId ];
Set<String> xxset = new Set<String>(); 
for (Case cs: Caslist) {
                xxset.add(cs.Number__c);
         }
          List<string> str = new List<string>();
          for (xxx__c xxinfo: [select id,Account__c,Case__c,Number__c from XXX__c where Number__c in :xxset]) { 
              str.add(xxinfo.Number__c);
              xxMap.put(str, xxinfo);
            }
if(Cas.Number__c!=null) {
            for (String num : Cas.Number__c.split(',') )
            {              
                if(num!=''  && !xxMap.containskey(num)) {   // Recieving error here  (Method does not exist or incorrect signature: void containskey(String) from the type Map<List<String>,XXX__c>)
}
}
}

Can someone correct me on what mistake i did in above snippet. 
Steven NsubugaSteven Nsubuga
Try this
Map <List<String>,XXX__c > xxMap = new Map <List<String>,XXX__c> ();
List<Case> Caslist= [SELECT Id,AccountID,Number__c FROM Case  WHERE ID =:CaseId ];
Set<String> xxset = new Set<String>(); 
for (Case cs: Caslist) {
                xxset.add(cs.Number__c);
         }
          List<string> str = new List<string>();
          for (xxx__c xxinfo: [select id,Account__c,Case__c,Number__c from XXX__c where Number__c in :xxset]) { 
              str.add(xxinfo.Number__c);
              xxMap.put(str, xxinfo);
            }
if(Cas.Number__c!=null) {
            for (String num : Cas.Number__c.split(',') )
            {              
                if(num!=''  && !xxMap.keyset().contains(num)) {   // Recieving error here  (Method does not exist or incorrect signature: void containskey(String) from the type Map<List<String>,XXX__c>)
}
}
}

 
SFDC pvSFDC pv
Hi @Steven ,

Got the below error when i tried keyset().contains(num) 

Method does not exist or incorrect signature: void contains(String) from the type Set<List<String>>
Steven NsubugaSteven Nsubuga
Try this 
Map <List<String>,XXX__c > xxMap = new Map <List<String>,XXX__c> ();
List<Case> Caslist= [SELECT Id,AccountID,Number__c FROM Case  WHERE ID =:CaseId ];
Set<String> xxset = new Set<String>(); 
for (Case cs: Caslist) {
	xxset.add(cs.Number__c);
}
List<string> str = new List<string>();
for (xxx__c xxinfo: [select id,Account__c,Case__c,Number__c from XXX__c where Number__c in :xxset]) { 
  str.add(xxinfo.Number__c);
  xxMap.put(str, xxinfo);
}
if(Cas.Number__c!=null) {
	for (String num : Cas.Number__c.split(',') )
	{   
		set<List<String>> ss = xxMap.keyset();
		List<String> sss = new List<String>();
		for (List<String> s: ss) {
			sss.addAll(s);
		}
		if(num!=''  && !sss.contains(num)) {   
		}
	}
}

 
SFDC pvSFDC pv
Hi steven,

Thanks for your prompt reply . Now error is gone. But in sss same numbers are added again hence its not went inside the loop and record is not getting inserted. Please see the log below

|[41]|DEBUG|str(1913321707, 1913321707)
[43]|DEBUG|FFMap{(1913321707, 1913321707)
|[49]|DEBUG|numbers1913321707
|[54]|DEBUG|sss(1913321707, 1913321707)
|[54]|DEBUG|sss(1913321707, 1913321707, 1913321707, 1913321707)
Steven NsubugaSteven Nsubuga
Map <List<String>,XXX__c > xxMap = new Map <List<String>,XXX__c> ();
List<Case> Caslist= [SELECT Id,AccountID,Number__c FROM Case  WHERE ID =:CaseId ];
Set<String> xxset = new Set<String>(); 
for (Case cs: Caslist) {
	xxset.add(cs.Number__c);
}
List<string> str = new List<string>();
for (xxx__c xxinfo: [select id,Account__c,Case__c,Number__c from XXX__c where Number__c in :xxset]) { 
  str.add(xxinfo.Number__c);
  xxMap.put(str, xxinfo);
}
set<List<String>> ss = xxMap.keyset();
List<String> sss = new List<String>();
for (List<String> s: ss) {
	sss.addAll(s);
}
if(Cas.Number__c!=null) {
	for (String num : Cas.Number__c.split(',') )
	{
		if(num!=''  && !sss.contains(num)) {   
		}
	}
}

 
SFDC pvSFDC pv
Hi,

Still same problem

|[41]|DEBUG|str(1925024562, 1925024562)
|[43]|DEBUG|FFMap{(1925024562, 1925024562)
|[47]|DEBUG|ss{(1925024562, 1925024562), (already output)}
|[51]|DEBUG|sss(1925024562, 1925024562)
|[51]|DEBUG|sss(1925024562, 1925024562, 1925024562, 1925024562)
|[56]|DEBUG|numbers1925024562