ID =“ xxxxxx”的错误帐户;不存在 [英] Error Account with Id = "xxxxxx" does not exist

查看:126
本文介绍了ID =“ xxxxxx”的错误帐户;不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建帐户和机会的custo工作流程。

I have a custo workflow that creates an account and opportunities.

有时我会遇到此错误:ID为= xxxxxx的帐户不存在。

Sometimes I have this error: Account with Id = "xxxxxx" does not exist.

知道在CRM中找到了帐户,我不知道代码有什么问题。

这是我的插件代码的步骤:

I don't know what's wrong in my code knowing that I find the account in the CRM.
Here are the steps of my plugin code:


  1. 按num查找帐户(如果不存在,我创建它们)

  2. 获取account =帐户

  3. 使用机会创建机会[[parentaccountid] =帐户;

  4. 错误消息!

  1. Find the account by num (if it doesn't exist, I create them)
  2. Get the account = Account
  3. Create an opportunity with Opportunity["parentaccountid"] = Account;
  4. Error message !

代码:

//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");

有时候,有几个工作流程在同一时间启动并且执行相同的操作(创建其他机会)

Sometimes there are several workflows that are started at the same time and that do the same thing (creating other opportunities)

推荐答案

您没有向我们展示整个插件,所以这只是一个猜测,但您可能正在分享您的IOrganizationService处于类级别,这会在代码中引起争用条件,并且一个线程在不同的上下文中创建一个新帐户,然后其服务被另一个线程覆盖,该线程在另一个不具有

You haven't shown us the entire plugin, so this is just a guess, but you're probably sharing your IOrganizationService at the class level, which is causing race conditions in your code, and one thread creates a new account in a different context, then its service gets overwritten by another thread, which is in a different database transaction that doesn't have the newly created account and it's erroring.

不要在线程间共享您的IOrganziationService!

Don't share your IOrganziationService across threads!

这篇关于ID =“ xxxxxx”的错误帐户;不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆