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

时间:2015-11-27 17:45:26

标签: c# salesforce

我在C#服务中使用SOAP Web Reference。

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

问题在于,我需要插入5000个案例,每个案例3秒钟需要大约4个小时来插入所有5000个案例。有没有办法让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就像我期待的那样

1 个答案:

答案 0 :(得分:0)

所以我想出了一种方法来执行此操作。

这个想法实际上是接受一个&#34; Case对象列表&#34;并立即发送所有这些,然后返回一个字符串数组的字符串数组。

我不确定如果我尝试打开太多会导致超时时间可能会在处理过程中通过(因此可以改进)会发生什么:

    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;
    }

原始版本中的错误处理过程也存在问题,但是这个问题解决了这个问题。我想我会发布我的解决方案以防其他人遇到这个问题......我无法在任何地方找到任何答案。