You need to sign in to do that
Don't have an account?
swapna muthiyalu
i have the code
set<string>mEmpId = new set<string>();
map<string,id> MEmpIds = new map<string,id>();
list<Contact> con = [SELECT id,eid,AccountId, from Contact where (eid__c IN :mEmpId);
for(Contact c : con)
{
if(mEmpId.contains(m.eid__c)
{
MEmpIds.put(m.eid__c, c.Id);
}
}
how to use map of map for map<id,map<string,id>> MEmpIds = new map<string,id>(); and validate the put is from respective account id
map<string,id> MEmpIds = new map<string,id>();
list<Contact> con = [SELECT id,eid,AccountId, from Contact where (eid__c IN :mEmpId);
for(Contact c : con)
{
if(mEmpId.contains(m.eid__c)
{
MEmpIds.put(m.eid__c, c.Id);
}
}
how to use map of map for map<id,map<string,id>> MEmpIds = new map<string,id>(); and validate the put is from respective account id
Can you explain what you are trying to accomplish? Additionally, in a Map<Id, Map<String, Id>> what do the following correspond to?
In map<string,id> MEmpIds = new map<string,id>(); i am considering contact and its id, now i want to add the corresponding account id also using
map<id,map<string,id>> MEmpIds.
so when [MEmpIds.put(m.eid__c, c.Id);] try to put i want to validate that the contact id is from the respective account.
say i have jack(jack account is Burlington textiles) as contact with some eid and when i try to put i have to validate that jack contact accound id is equal to burlington account id.
This iam trying to achieve.
Based on your requirement it makes more sense to store it as follows Map<AccountId, (ContactId, ContactRecordInstance)>. This will reduce your iterations and facilitate the type of search you intedn to perform. The sample code to do so is as follows.
i have one clarification here when i do like this
set<string>mEmpId = new set<string>();
map<id,map<string,id> > MEmpIds = new map<id, map<string,id>>();
list<Contact> con = [SELECT id,eid,AccountId, from Contact where (eid__c IN :mEmpId);
for(Contact c : con)
{
if(mEmpId.contains(c.eid__c)
{
mEmpIds.put(c,accountid).put(c.eid__c, c.Id);
0r can i write like this
mEmpIds.put(c,accountid,c.eid__c, c.Id);
or
mEmpIds.get(c,accountid).put(c.eid__c, c.Id);
}
}
will this work or i need to loop first map<string,id> and add to the outer map as u mentioned.
Please advice.
Swapna
In order to verify this, paste this code in Developer Console > Debug > Execute Anonymous Window and click Execute. Check the DEBUG checkbox in the log window to filter only the System.debug() statements from the entire log and check the values that are printed.