我在Lead实体上有帐户和联系人查询字段。我想获取联系人的帐户名称和电子邮件地址。
我收到无效参数错误。
代码:
public EntityCollection GetDetails()
{
string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='lead'>
<attribute name='fullname' />
<attribute name='leadid' />
<attribute name='new_contact'/>
<attribute name='new_account'/>
<order attribute='fullname' descending='false' />
<filter type='and'>
<condition attribute='leadqualitycode' operator='eq' value='1' />
</filter>
</entity>
</fetch>";
EntityCollection records = service.RetrieveMultiple(new FetchExpression(fetchXML));
return records;
}
public string GetAccountDetail(EntityCollection records)
{
if (records.Entities.Count != 0)
{
accountid = records.Entities[0].GetAttributeValue<Guid>("new_account");
tracingService.Trace("AccountId :" + accountid);
Entity accountDetails = service.Retrieve("account", accountid, new ColumnSet("name"));
string accountname = accountDetails.Attributes["name"].ToString();
tracingService.Trace("AccountName :" + accountname);
return accountname;
}
return name;
}
答案 0 :(得分:0)
更改此行
accountid = records.Entities[0].GetAttributeValue<Guid>("new_account");
进入
accountid = records.Entities[0].GetAttributeValue<EntityReference>("new_account").Id;
因为这是一次查找。