Example #1
0
        internal void InstallTrigger(string objectName)
        {
            if (objectName.Contains(_appNamespace + "__"))
            {
                return;
            }

            UninstallTrigger(objectName);

            string triggerName = objectName.Replace("__c", "_custom") + "_" + TRIGGER_NAME;
            string triggerBody =
                new Dictionary <string, string>
            {
                { "{TRIGGER_NAME}", triggerName },
                { "{TRIGGER_OBJECT}", objectName },
                { "{APP_NAMESPACE}", _appNamespace },
                { "{TIMESTAMP}", DateTime.Now.ToUniversalTime().ToString("r") }
            }.Aggregate(Resources.SFIntTrigger, (c, p) => c.Replace(p.Key, p.Value));

            _apexService.Timeout = 3600 * 1000;

            CompileAndTestResult result = _apexService.compileAndTest(new CompileAndTestRequest
            {
                triggers  = new[] { triggerBody },
                checkOnly = true
            });

            ProcessTriggerInstallationResults(result, triggerName);

            result = _apexService.compileAndTest(new CompileAndTestRequest {
                triggers = new[] { triggerBody }
            });

            ProcessTriggerInstallationResults(result, triggerName);
        }
Example #2
0
        private static void ProcessTriggerInstallationResults(CompileAndTestResult result, string triggerName)
        {
            if (result.success)
            {
                return;
            }

            var stringBuilder = new StringBuilder();

            foreach (CompileTriggerResult triggerResult in result.triggers.Where(r => !string.IsNullOrEmpty(r.problem)))
            {
                stringBuilder.AppendLine("Could not create " + triggerName);
                stringBuilder.AppendLine(triggerResult.problem);
            }

            string message = stringBuilder.ToString();

            if (!string.IsNullOrEmpty(message))
            {
                throw new Exception(message);
            }
        }