【发布时间】:2026-01-19 03:25:01
【问题描述】:
我有一个创建帐户和机会的托管工作流。
有时我会遇到此错误:Id = "xxxxxx" 的帐户不存在。
知道我在 CRM 中找到了帐户,但我不知道我的代码有什么问题。
以下是我的插件代码的步骤:
- 按 num 查找帐户(如果不存在,我创建它们)
- 获取帐号 = 帐号
- 使用 Opportunity["parentaccountid"] = Account 创建机会;
- 错误信息!
代码:
//Get opportunity
Guid id = retrieveOpportunity<string>("opportunity", "new_numero", numero, service);
Entity eOpportunity;
if (id != Guid.Empty)
{
eOpportunity = new Entity("opportunity", id);
}
else
{
eOpportunity = new Entity("opportunity");
}
//Get account
EntityReference eAccount = retrieveAccount<string>(accountCode, "account", "new_code", service);
if (eAccount == null)
{
eAccount = new Entity("account", "new_code", accountCode);
eAccount["name"] = "name";
UpsertRequest usMessage = new UpsertRequest()
{
Target = eAccount
};
//create account
UpsertResponse usResponse = (UpsertResponse)this._service.Execute(usMessage);
eOpportunity["parentaccountid"] = usResponse.Target;
}
else
{
eOpportunity["parentaccountid"] = eAccount;
}
UpsertRequest req = new UpsertRequest()
{
Target = eOpportunity
};
//upsert opportunity
UpsertResponse resp = (UpsertResponse)service.Execute(req);
if (resp.RecordCreated)
tracer.Trace("New opportunity");
else
tracer.Trace("Opportunity updated");
有时会同时启动多个工作流并执行相同的操作(创造其他机会)
【问题讨论】:
-
向我们展示实际代码而不是伪代码..:)
标签: c# dynamics-crm dynamics-crm-online dynamics-crm-365