在一次登录中创建多个SalesForce案例

本文关键字:创建 SalesForce 案例 登录 一次 | 更新日期: 2023-09-27 18:24:42

为此,我在C#服务中使用了SOAP Web引用。

如果我在同一个连接中多次调用(在我的SForceManager类中)CreateSForceCase(),我会收到相同的确切CaseNumber,直到连接超时并重新连接(或者如果我为每个连接创建一个新连接)。

这个问题是,我需要插入多达5000个案例,每个案例3秒,插入所有5000个案例大约需要4个小时。有没有办法让API知道我每次创建一个全新的案例而不注销?

这是我的经理代码:

public String CreateSForceCase(Case sfCase, out string errMsg)
    {
        //Verify that we are already authenticated, if not
        //call the login function to do so
        if (!isConnected()) login();
        errMsg = "";
        sObject[] objCases = new sObject[1];
        for (int j = 0; j < objCases.Length; j++)
            objCases[j] = sfCase;
        //create the object(s) by sending the array to the web service
        SaveResult[] sr = _Binding.create(objCases);
        for (int j = 0; j < sr.Length; j++)
        {
            if (sr[j].success)
            {
                //save the account ids in a class array
                if (_cases == null)
                    _cases = new string[] { sr[j].id };
                else
                {
                    string[] tempcases = null;
                    tempcases = new string[_cases.Length + 1];
                    for (int i = 0; i < _cases.Length; i++)
                        tempcases[i] = _cases[i];
                    tempcases[_cases.Length] = sr[j].id;
                    _cases = tempcases;
                }
                return getCaseNumberFromCaseId(_cases[0]);
            }
            else
            {
                //there were errors during the create call, go through the errors
                //array and write them to the screen
                for (int i = 0; i < sr[j].errors.Length; i++)
                {
                    //get the next error
                    Error err = sr[j].errors[i];
                    errMsg = err.message;
                }
            }
        }
        return string.Empty;
    }

并且内部获取案例#的调用是:

public String getCaseNumberFromCaseId(string caseId)
    {
        if (!isConnected()) login();
        sObject[] ret = _Binding.retrieve("CaseNumber", "Case", new string[] { caseId });
        if (ret != null)
            return ((Case)ret[0]).CaseNumber;
        else
            return string.Empty;
    }

所以类似于:

SForceManager manager = new SForceManager();
string case1 = manager.CreateSForceCase(...);
string case2 = manager.CreateSForceCase(...);
string case3 = manager.CreateSForceCase(...);

则case1==case2==case3

但如果我这样做:

SForceManager manager = new SForceManager();
string case1 = manager.CreateSForceCase(...);
SForceManager manager = new SForceManager();
string case2 = manager.CreateSForceCase(...);
SForceManager manager = new SForceManager();
string case3 = manager.CreateSForceCase(...);

那么case1!=case2!=case3就像我期待的

在一次登录中创建多个SalesForce案例

所以我找到了一种执行此操作的方法。

这个想法实际上是接收一个"Case对象"列表,并一次发送所有这些对象,然后返回一个Case id的字符串数组。

我不确定如果我试着打开太多会发生什么,这样超时期可能会在处理过程中过去(所以它还可以改进):

    public String[] CreateSForceCases(Case[] sfCase, out List<string> errMsg)
    {
        String[] toRet = new string[sfCase.Length];
        errMsg = new List<string>();
        //Verify that we are already authenticated, if not
        //call the login function to do so
        if (!isConnected()) login();
        //errMsg = "";
        sObject[] objCases = new sObject[sfCase.Length];
        for (int j = 0; j < objCases.Length; j++)
            objCases[j] = sfCase[j];
        //create the object(s) by sending the array to the web service
        SaveResult[] sr = _Binding.create(objCases);
        for (int j = 0; j < sr.Length; j++)
        {
            if (sr[j].success)
            {
                //save the account ids in a class array
                if (_cases == null)
                    _cases = new string[] { sr[j].id };
                else
                {
                    string[] tempcases = null;
                    tempcases = new string[_cases.Length + 1];
                    for (int i = 0; i < _cases.Length; i++)
                        tempcases[i] = _cases[i];
                    tempcases[_cases.Length] = sr[j].id;
                    _cases = tempcases;
                }
                toRet[j] = getCaseNumberFromCaseId(_cases[j]);
            }
            else
            {
                //there were errors during the create call, go through the errors
                //array and write them to the screen
                for (int i = 0; i < sr[j].errors.Length; i++)
                {
                    //get the next error
                    Error err = sr[j].errors[i];
                    errMsg.Add(err.message);
                }
            }
        }
        return toRet;
        //return null;
    }

在最初的错误处理过程中也有一个问题,但这次解决了这个问题。我想我会发布我的解决方案,以防其他人遇到这个问题。。。我在任何地方都找不到问题的答案。