You need to sign in to do that
Don't have an account?
Saad Ahmad 49
What would be the SOQL statement to return all the account ID's for various contacts IDs?
Trying to get all account ID's based on a list of contact ID's I have. Any example SOQL statements would be great.
Thanks!
Thanks!
Try Below Code Please Mark It As Best Answer If it Helps
Thank You!
{
public static void mapMethod()
{
Map<Id,List<Contact>> accountToContactMap=new Map<id,List<Contact>>();
List<Contact> contactlist=new List<Contact>([SELECT Id,Name,AccountId,email FROM CONTACT WHERE AccountId!=null limit 100]);
for(Contact con:contactlist)
{
if(!accountToContactMap.containsKey(con.AccountId))
{
List<Contact> conls=new List<Contact>();
conls.add(con);
accountToContactMap.put(con.AccountId,conls);
}
else
{
List<contact> conls=accountToContactMap.get(con.AccountId);
conls.add(con);
accountToContactMap.put(con.AccountId,conls);
}
}
system.debug('Map of Account: '+accountToContactMap);
}
}
you need to try below code if you have list of contact ids. below class will return list of Account ids that contains in contact ids that you passed by parameters.
don't forget to mark it as best answer if it help you.
Thank you
did you try any code if not then please try it and mark it as best answer.
Thank you