/// <summary> /// Create a new checkpoint. /// </summary> /// <param name="entityId">The id of the file to create a checkpoint in.</param> /// <param name="fileName">The name of the file to create a checkpoint in.</param> /// <param name="lineNumber">The line number in the file to create the checkpoint for.</param> /// <param name="iteration">The number of iterations before the checkpoint is processed.</param> /// <param name="isHeapDump">If true a heap dump will be collected with the checkpoint.</param> /// <param name="script">An optional script to run with the checkpoint.</param> /// <param name="scriptType">The type of script specified.</param> /// <returns>The newly created checkpoint.</returns> private Checkpoint CreateCheckpoint( string entityId, string fileName, int lineNumber, int iteration, bool isHeapDump, string script, CheckpointScriptType scriptType) { if (entityId == null) { throw new ArgumentNullException("entityId"); } SalesForceAPI.Tooling.ApexExecutionOverlayAction action = new SalesForceAPI.Tooling.ApexExecutionOverlayAction(); action.ActionScript = script; action.ActionScriptType = scriptType.ToString(); action.ExecutableEntityId = entityId; action.ExpirationDate = DateTime.Now.AddDays(1); action.ExpirationDateSpecified = true; action.IsDumpingHeap = isHeapDump; action.IsDumpingHeapSpecified = true; action.Iteration = iteration; action.IterationSpecified = true; action.Line = lineNumber; action.LineSpecified = true; action.ScopeId = _client.User.Id; SalesForceAPI.Tooling.createResponse response = _client.ToolingClient.create(new SalesForceAPI.Tooling.createRequest( new SalesForceAPI.Tooling.SessionHeader() { sessionId = _client.SessionId }, new SalesForceAPI.Tooling.sObject[] { action })); if (response != null && response.result != null && response.result.Length == 1) { if (!response.result[0].success) { StringBuilder sb = new StringBuilder(); if (response.result[0].errors != null) { foreach (SalesForceAPI.Tooling.Error err in response.result[0].errors) { sb.AppendLine(err.message); } } throw new Exception("Couldn't create checkpoint: \r\n" + sb.ToString()); } } else { throw new Exception("Couldn't create checkpoint: Invalid response received."); } action.Id = response.result[0].id; return(new Checkpoint(action, fileName)); }
/// <summary> /// Create new log listener. /// </summary> /// <param name="traceEntityId">TraceEntityId.</param> /// <param name="tracedEntityName">TracedEntityName.</param> /// <param name="scopeId">ScopeId.</param> /// <param name="scopeName">ScopeName.</param> /// <param name="expirationDate">ExpirationDate.</param> /// <param name="codeLevel">CodeLevel.</param> /// <param name="visualForceLevel">VisualForceLevel.</param> /// <param name="profilingLevel">ProfilingLevel.</param> /// <param name="calloutLevel">CalloutLevel.</param> /// <param name="databaseLevel">DatabaseLevel.</param> /// <param name="systemLevel">SystemLevel.</param> /// <param name="validationLevel">ValidationLevel.</param> /// <param name="workflowLevel">WorkflowLevel.</param> /// <returns>The newly created log listener.</returns> public LogListener CreateLogListener( string traceEntityId, string tracedEntityName, string scopeId, string scopeName, DateTime expirationDate, LogLevel codeLevel, LogLevel visualForceLevel, LogLevel profilingLevel, LogLevel calloutLevel, LogLevel databaseLevel, LogLevel systemLevel, LogLevel validationLevel, LogLevel workflowLevel) { if (traceEntityId == null) { throw new ArgumentNullException("traceEntityId"); } SalesForceAPI.Tooling.TraceFlag traceFlag = new SalesForceAPI.Tooling.TraceFlag(); traceFlag.ApexCode = codeLevel.ToString().ToUpper(); traceFlag.ApexProfiling = profilingLevel.ToString().ToUpper(); traceFlag.Callout = calloutLevel.ToString().ToUpper(); traceFlag.Database = databaseLevel.ToString().ToUpper(); traceFlag.ExpirationDate = expirationDate.ToUniversalTime(); traceFlag.ExpirationDateSpecified = true; traceFlag.ScopeId = scopeId; traceFlag.System = systemLevel.ToString().ToUpper(); traceFlag.TracedEntityId = traceEntityId; traceFlag.Validation = validationLevel.ToString().ToUpper(); traceFlag.Visualforce = visualForceLevel.ToString().ToUpper(); traceFlag.Workflow = workflowLevel.ToString().ToUpper(); SalesForceAPI.Tooling.createResponse response = _client.ToolingClient.create(new SalesForceAPI.Tooling.createRequest( new SalesForceAPI.Tooling.SessionHeader() { sessionId = _client.SessionId }, new SalesForceAPI.Tooling.sObject[] { traceFlag })); if (response != null && response.result != null && response.result.Length == 1) { if (!response.result[0].success) { StringBuilder sb = new StringBuilder(); if (response.result[0].errors != null) { foreach (SalesForceAPI.Tooling.Error err in response.result[0].errors) { sb.AppendLine(err.message); } } throw new Exception("Couldn't create log parameters: \r\n" + sb.ToString()); } } else { throw new Exception("Couldn't create log parameters: Invalid response received."); } traceFlag.Id = response.result[0].id; return(new LogListener(traceFlag, scopeName, tracedEntityName)); }