[英]How to get all contacts of an Account and build an email List in MS Dynamics CRM?
我有一個帳戶ID,並希望獲得該帳戶下的聯系人集合以建立電子郵件列表。
//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;
}
您可以在聯系人實體中找到客戶鍵“ parentcustomerid”。 您可以按以下帳戶ID獲取聯系人集合。
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.