예제 #1
0
        public BatchSubRequest UpsertExternal(string objectName, string externalFieldName, string externalId, object record)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (string.IsNullOrEmpty(externalId))
            {
                throw new ArgumentNullException(nameof(externalId));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var richInput = Dnf.UnFlatten(JObject.FromObject(record));
            var request   = new BatchSubRequest
            {
                RichInput = Dnf.Omit(richInput, externalFieldName),
                Method    = "PATCH",
                Url       = $"sobjects/{objectName}/{externalFieldName}/{Uri.EscapeDataString(externalId)}"
            };

            BatchRequests.Add(request);
            return(request);
        }
        public CompositeSubRequest UpsertExternal(string referenceId, string objectName, string externalFieldName, string externalId, object record)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (string.IsNullOrEmpty(externalId))
            {
                throw new ArgumentNullException(nameof(externalId));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var body    = Dnf.UnFlatten(JObject.FromObject(record));
            var request = new CompositeSubRequest
            {
                Body        = Dnf.Omit(body, externalFieldName),
                Method      = "PATCH",
                ReferenceId = referenceId,
                Url         = $"sobjects/{objectName}/{externalFieldName}/{Uri.EscapeDataString(externalId)}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
        public CompositeSubRequest Update(string referenceId, string objectName, string recordId, object record)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (string.IsNullOrEmpty(recordId))
            {
                throw new ArgumentNullException(nameof(recordId));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var body    = Dnf.UnFlatten(JObject.FromObject(record));
            var request = new CompositeSubRequest
            {
                Body        = Dnf.Omit(body, "Id"),
                Method      = "PATCH",
                ReferenceId = referenceId,
                Url         = $"sobjects/{objectName}{recordId}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
예제 #4
0
        public BatchSubRequest Update(string objectName, string recordId, object record)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (string.IsNullOrEmpty(recordId))
            {
                throw new ArgumentNullException(nameof(recordId));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var richInput = Dnf.UnFlatten(JObject.FromObject(record));
            var request   = new BatchSubRequest
            {
                RichInput = Dnf.Omit(richInput, "Id"),
                Method    = "PATCH",
                Url       = $"sobjects/{objectName}/{recordId}"
            };

            BatchRequests.Add(request);
            return(request);
        }
예제 #5
0
        public BatchSubRequest UpsertExternal(string objectName, string externalFieldName, object record)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var richInput = Dnf.UnFlatten(JObject.FromObject(record));

            return(UpsertExternal(objectName, externalFieldName, richInput[externalFieldName]?.ToString() ?? string.Empty, Dnf.Omit(richInput, externalFieldName)));
        }
예제 #6
0
        public BatchSubRequest Update(string objectName, object record)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var richInput = Dnf.UnFlatten(JObject.FromObject(record));

            return(Update(objectName, richInput["Id"]?.ToString() ?? string.Empty, Dnf.Omit(richInput, "Id")));
        }
        public CompositeSubRequest UpsertExternal(string referenceId, string objectName, string externalFieldName, object record)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var body = Dnf.UnFlatten(JObject.FromObject(record));

            return(UpsertExternal(referenceId, objectName, externalFieldName, body[externalFieldName]?.ToString() ?? string.Empty, Dnf.Omit(body, externalFieldName)));
        }
예제 #8
0
        public BatchSubRequest Create(string objectName, object record)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var request = new BatchSubRequest
            {
                RichInput = Dnf.UnFlatten(JObject.FromObject(record)),
                Url       = $"sobjects/{objectName}"
            };

            BatchRequests.Add(request);
            return(request);
        }
예제 #9
0
        public IList <CompositeSubRequest> Update <T>(string referenceId, bool allOrNone, IList <T> records)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (records == null || !records.Any())
            {
                throw new ArgumentNullException(nameof(records));
            }

            if (allOrNone && records.Count > 200)
            {
                throw new ArgumentOutOfRangeException(nameof(records));
            }
            var result = new List <CompositeSubRequest>();

            foreach (var(chunk, chunkIdx) in EnumerableChunk.Create(records, 200).Select((chunk, chunkIdx) => (chunk, chunkIdx)))
            {
                var bodyRecords = JToken.FromObject(chunk.Select(record => record == null ? new JObject() : Dnf.UnFlatten(JObject.FromObject(record))));
                var request     = new CompositeSubRequest
                {
                    ResponseType = "collections",
                    Body         = new JObject
                    {
                        ["allOrNone"] = allOrNone,
                        ["records"]   = bodyRecords
                    },
                    Method      = "PATCH",
                    ReferenceId = $"{referenceId}_{chunkIdx}",
                    Url         = "composite/sobjects"
                };
                CompositeRequests.Add(request);
                result.Add(request);
            }
            return(result);
        }