Reputation: 7429
I've an account Id, and would like to get the collection of contacts under the account to build an email list.
//build up Email
private Email BuildEmail(ActivityParty allcontacts){.... build my emailhere}
private List<Entity> GetAllContactsFromAccountId(Guid accountId, List<Entity> toList)
{
//how can I get all the contacts here
foreach (Entity contact in Account.Contact.Entities)//????
{
Entity activityParty = new Entity("activityparty");
activityParty["partyid"] = new EntityReference("??", e.Id);
if (toList.Any(t => t.GetAttributeValue<EntityReference>("partyid").Id == e.Id)) continue;
toList.Add(activityParty);
}
return toList;
}
Upvotes: 0
Views: 2289
Reputation: 1453
You can find the Account key "parentcustomerid" in contact entity. you can get contact collection by account id as below.
private EntityCollection getContactByAccountId(IOrganizationService service, Guid accountId)
{
QueryExpression query = new QueryExpression("contact");
query.ColumnSet = new ColumnSet(new string[] { "contactid", "fullname" });
query.Criteria.AddCondition(new ConditionExpression("parentcustomerid", ConditionOperator.Equal, accountId))
return service.RetrieveMultiple(query);
}
Upvotes: 1