示例#1
0
        /// <summary>
        /// Updates a list of sobject records
        /// </summary>
        private PopulateObjectResult UpdateRecords(string objectName, List <sObject> updateList)
        {
            var result = new PopulateObjectResult();

            result.ApiName = objectName;

            int  done    = 0;
            bool allDone = false;

            if (updateList.Count == 0)
            {
                allDone = true;
            }
            while (!allDone)
            {
                var batch = updateList.Skip(done).Take(100).ToList();
                done += batch.Count;
                if (done >= updateList.Count)
                {
                    allDone = true;
                }

                var updateRes = _targetTasks.UpdateSObjects(objectName,
                                                            batch.ToArray());

                for (int i = 0; i < updateRes.Length; i++)
                {
                    if (updateRes[i].Success)
                    {
                        result.SuccessCount += 1;
                    }
                    else
                    {
                        logger.WarnFormat("Error when updating {0} {1} in target: {2}",
                                          objectName, batch[i].Id, updateRes[i].ErrorMessage);
                        result.FailCount += 1;
                    }
                }
            }

            logger.DebugFormat("Object {0} updated. Attempted {1} Success {2} Failed {3}",
                               objectName, updateList.Count, result.SuccessCount, result.FailCount);

            return(result);
        }
示例#2
0
        private void UpdateRecursiveField(string apiName, List <ObjectTransformer.sObjectWrapper> workingList, string recursiveRelationshipField)
        {
            logger.DebugFormat("Object {0} has a recursive relation field {1}, now doing second pass to set it....",
                               apiName, recursiveRelationshipField);

            // make a new list of sObjects to do the update
            List <sObject> updateList = new List <sObject>();

            foreach (var wrapLoop in workingList)
            {
                if (!string.IsNullOrEmpty(wrapLoop.RecursiveRelationshipOriginalId))
                {
                    var upd = new sObject();

                    upd.type = wrapLoop.sObj.type;
                    upd.Id   = wrapLoop.NewId;
                    XmlDocument dummydoc    = new XmlDocument();
                    XmlElement  recursiveEl = dummydoc.CreateElement(recursiveRelationshipField);

                    string replaceValue = _relationMapper.RecallNewId(apiName, wrapLoop.RecursiveRelationshipOriginalId);

                    if (replaceValue == null)
                    {
                        logger.DebugFormat("Object {0} {1} recursive field {2} have value {3} could not translate - will ignore",
                                           apiName, wrapLoop.OriginalId, recursiveRelationshipField, wrapLoop.RecursiveRelationshipOriginalId);
                    }
                    else
                    {
                        recursiveEl.InnerText = replaceValue;

                        upd.Any = new XmlElement[] { recursiveEl };

                        updateList.Add(upd);
                    }
                }
            }

            logger.DebugFormat("{0} rows in Object {1} have recursive relation {2} to update ....",
                               updateList.Count(), apiName, recursiveRelationshipField);

            // update objects in batches
            int  successCount = 0;
            int  failCount    = 0;
            int  done         = 0;
            bool allDone      = false;

            if (updateList.Count == 0)
            {
                allDone = true;
            }
            while (!allDone)
            {
                var batch = updateList.Skip(done).Take(100).ToList();
                done += batch.Count;
                if (done >= updateList.Count)
                {
                    allDone = true;
                }

                var updateRes = _targetTasks.UpdateSObjects(apiName,
                                                            batch.ToArray());

                for (int i = 0; i < updateRes.Length; i++)
                {
                    if (updateRes[i].Success)
                    {
                        successCount += 1;
                    }
                    else
                    {
                        logger.WarnFormat("Error when updating {0} {1} in target: {2}",
                                          apiName, batch[i].Id, updateRes[i].ErrorMessage);
                        failCount += 1;
                    }
                }
            }
            logger.DebugFormat("Object {0} recursive relation {1} updated. Attempted {2} Success {3} Failed {4}",
                               apiName, recursiveRelationshipField, updateList.Count, successCount, failCount);
        }