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;
}
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.