You need to sign in to do that
Don't have an account?
Salesforce Beginner
To create a map of parent and child.
Hello All,
I have a contact object and custom__c object. Where in Custom__c has a lookup relation to contact. My requirement is, for every contact record, have to loop through all the child records. For this I need a map<contact_Id, List<custom__c>>.
I am trying different ways to do it with no luck. Any thoughts on this is appreciated.
Once I have a map, I am planning to do the following:
for (ID conid: map.keyset())
{
for(custom__c cust : map.get(conid))
{
if(cust.status==True)
{
// update few fields on contact
}
}
}
I have a contact object and custom__c object. Where in Custom__c has a lookup relation to contact. My requirement is, for every contact record, have to loop through all the child records. For this I need a map<contact_Id, List<custom__c>>.
I am trying different ways to do it with no luck. Any thoughts on this is appreciated.
Once I have a map, I am planning to do the following:
for (ID conid: map.keyset())
{
for(custom__c cust : map.get(conid))
{
if(cust.status==True)
{
// update few fields on contact
}
}
}
Please try below code :-
Option 1:-
Option 2:-
Please mark this as solution if this will help you. So that if any one has same issue this post can help
All Answers
Please try below code :-
Option 1:-
Option 2:-
Please mark this as solution if this will help you. So that if any one has same issue this post can help
List<Account> lstAccount = [SELECT Id, name, (SELECT Id, Name FROM Contacts) FROM Account]; for(Account acc : lstAccount) { this.accountContactMap.put(acc, acc.Contacts);
}
System.debug(this.accountContactMap);