You need to sign in to do that
Don't have an account?
sumit d
Creating map two ids as key in map
hi All,
i Created a map in which i am taking two ids as key .i created the map as below:-
Map<Id,FBG_Family__c> mapAlreadyexitFamily = new Map<Id,FBG_Family__c>();
for(FBG_Family__c existFamily : [select id, Name, Sister_Company__c, Sister_Company2__c FROM FBG_Family__c ]){
String key = String.valueOf(existFamily.Sister_Company__c) + String.valueOf(existFamily.Sister_Company__c);
mapAlreadyexitFamily.put(key,existFamily);
}
but its giving me error:- Invalid id: nullnull.
how can i create a map having two ids as a key and get value related to that key which is a record.
Any suggestions, how to do it?
i Created a map in which i am taking two ids as key .i created the map as below:-
Map<Id,FBG_Family__c> mapAlreadyexitFamily = new Map<Id,FBG_Family__c>();
for(FBG_Family__c existFamily : [select id, Name, Sister_Company__c, Sister_Company2__c FROM FBG_Family__c ]){
String key = String.valueOf(existFamily.Sister_Company__c) + String.valueOf(existFamily.Sister_Company__c);
mapAlreadyexitFamily.put(key,existFamily);
}
but its giving me error:- Invalid id: nullnull.
how can i create a map having two ids as a key and get value related to that key which is a record.
Any suggestions, how to do it?
Check the containsKey in Map. That should work.
Regards,
Avishek
All Answers
You have taken Map parameter as id and sObject however adding a Srting which is why you are getting error invalid id.
Change the Parameter you should be able to add the values to Map.
Regards,
Avishek
i want to create record when the record is not present in the map so i tried like below:-
//creating junction object records
List<FBG_Family__c> ListFBGFamily = new List<FBG_Family__c>();
for (Account acc : accounts)
{
List<Account> DuplicateAccount = mapDuplicateAccNameToIds.get(acc.Name);
System.debug('DuplicateAccount'+DuplicateAccount);
for(Account Acc1 : DuplicateAccount ){
FBG_Family__c Family = new FBG_Family__c();
Family.Sister_Company__c = acc.id;
if( acc.Id != Acc1.Id){
Family.Sister_Company2__c = Acc1.id;
String key = ''+ Family.Sister_Company__c + Family.Sister_Company2__c;
if(Family != mapAlreadyexitFamily.get(key)){
ListFBGFamily.add(Family);
}
}
}
}
but still its inserting records which r already present in the map.
how to solve this any suggestions?
Check the containsKey in Map. That should work.
Regards,
Avishek