public CompositeSubRequest Delete(string referenceId, string objectName, string recordId)
        {
            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));
            }

            var request = new CompositeSubRequest
            {
                Method      = "DELETE",
                ReferenceId = referenceId,
                Url         = $"sobjects/{objectName}/{recordId}"
            };

            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);
        }
        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);
        }
Ejemplo n.º 4
0
        public CompositeSubRequest QuickActionsDefaultValues(string referenceId, string objectName, string actionName, string contextId)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (string.IsNullOrEmpty(actionName))
            {
                throw new ArgumentNullException(nameof(actionName));
            }
            if (string.IsNullOrEmpty(contextId))
            {
                throw new ArgumentNullException(nameof(contextId));
            }

            var request = new CompositeSubRequest
            {
                Method      = "GET",
                ReferenceId = referenceId,
                Url         = $"sobjects/{objectName}/quickActions/{actionName}/defaultValues/{contextId}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
        public CompositeSubRequest Retrieve(string referenceId, string objectName, string recordId, params string[] fields)
        {
            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));
            }

            var request = new CompositeSubRequest
            {
                Method      = "GET",
                ReferenceId = referenceId,
                Url         = fields.Length > 0
                    ? $"sobjects/{objectName}/{recordId}?fields={string.Join(",", fields.Select(Uri.EscapeDataString))}"
                    : $"sobjects/{objectName}/{recordId}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
Ejemplo n.º 6
0
        //public IList<CompositeSubRequest> UpsertExternal<T>(string referenceId, string objectName, string externalFieldName, IList<T> records)
        //{
        //    return UpsertExternal(referenceId, false, externalFieldName, records);
        //}

        //public IList<CompositeSubRequest> UpsertExternal<T>(string referenceId, bool allOrNone, string externalFieldName, IList<T> records)
        //{
        //    if (string.IsNullOrEmpty(referenceId)) throw new ArgumentNullException("referenceId");
        //    if (records == null || !records.Any()) throw new ArgumentNullException("records");

        //    var result = new List<CompositeSubRequest>();

        //    if (allOrNone && records.Count() > 200) throw new ArgumentOutOfRangeException("records");

        //    foreach (var (chunk, chunkIdx) in EnumerableChunk.Create(records, 200).Select((chunk, chunkIdx) => (chunk, chunkIdx)))
        //    {
        //        var bodyRecords = JToken.FromObject(chunk.Select(record => 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;
        //}

        public IList <CompositeSubRequest> Delete(string referenceId, bool allOrNone, params string[] ids)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (ids == null || ids.Length == 0)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            if (allOrNone && ids.Length > 200)
            {
                throw new ArgumentOutOfRangeException(nameof(ids));
            }

            var result = new List <CompositeSubRequest>();

            foreach (var(chunk, chunkIdx) in EnumerableChunk.Create(ids, 200).Select((chunk, chunkIdx) => (chunk, chunkIdx)))
            {
                var request = new CompositeSubRequest
                {
                    ResponseType = "collections",
                    Method       = "DELETE",
                    ReferenceId  = $"{referenceId}_{chunkIdx}",
                    Url          = $"composite/sobjects?ids={string.Join(",", chunk.Select(Uri.EscapeDataString))}{(allOrNone ? "&allOrNone=" : "")}"
                };
                CompositeRequests.Add(request);
                result.Add(request);
            }
            return(result);
        }
Ejemplo n.º 7
0
        public CompositeSubRequest NamedLayouts(string referenceId, string objectName, string layoutName)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (string.IsNullOrEmpty(layoutName))
            {
                throw new ArgumentNullException(nameof(layoutName));
            }

            var request = new CompositeSubRequest
            {
                Method      = "GET",
                ReferenceId = referenceId,
                Url         = $"sobjects/{objectName}/describe/namedLayouts/{layoutName}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
Ejemplo n.º 8
0
        public CompositeSubRequest DeleteExternal(string referenceId, string objectName, string externalFieldName, string externalId)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (string.IsNullOrEmpty(externalFieldName))
            {
                throw new ArgumentNullException(nameof(externalFieldName));
            }
            if (string.IsNullOrEmpty(externalId))
            {
                throw new ArgumentNullException(nameof(externalId));
            }

            var request = new CompositeSubRequest
            {
                Method      = "DELETE",
                ReferenceId = referenceId,
                Url         = $"sobjects/{objectName}/{externalFieldName}/{Uri.EscapeDataString(externalId)}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
        public CompositeSubRequest Describe(string referenceId)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }

            var request = new CompositeSubRequest
            {
                Method      = "GET",
                ReferenceId = referenceId,
                Url         = "sobjects/describe"
            };

            CompositeRequests.Add(request);
            return(request);
        }
Ejemplo n.º 10
0
        public CompositeSubRequest CreateTree(string referenceId, string objectName, IEnumerable <IAttributedObject> objectTree)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }

            var request = new CompositeSubRequest
            {
                Body        = new RecordsObject(objectTree),
                Method      = "POST",
                ReferenceId = referenceId,
                Url         = $"composite/tree/{objectName}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
Ejemplo n.º 11
0
        public IList <CompositeSubRequest> RetrieveExternal(string referenceId, string objectName, string externalFieldName, IList <string> externalIds, params string[] fields)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            if (string.IsNullOrEmpty(externalFieldName))
            {
                throw new ArgumentNullException(nameof(externalFieldName));
            }
            if (externalIds == null || !externalIds.Any())
            {
                throw new ArgumentNullException(nameof(externalIds));
            }
            if (fields == null || fields.Length == 0)
            {
                throw new ArgumentNullException(nameof(fields));
            }

            var result = new List <CompositeSubRequest>();

            foreach (var(chunk, chunkIdx) in EnumerableChunk.Create(externalIds, 2000).Select((chunk, chunkIdx) => (chunk, chunkIdx)))
            {
                var request = new CompositeSubRequest
                {
                    ResponseType = "collections",
                    Body         = new JObject
                    {
                        ["ids"]    = JToken.FromObject(chunk.Select(id => id)),
                        ["fields"] = JToken.FromObject(fields)
                    },
                    Method      = "POST",
                    ReferenceId = $"{referenceId}_{chunkIdx}",
                    Url         = $"composite/sobjects/{objectName}/{externalFieldName}"
                };
                CompositeRequests.Add(request);
                result.Add(request);
            }
            return(result);
        }
        public CompositeSubRequest GetUpdated(string referenceId, string objectName, DateTime startDateTime, DateTime endDateTime)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }

            var sdt = Uri.EscapeDataString(startDateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss+00:00", CultureInfo.InvariantCulture));
            var edt = Uri.EscapeDataString(endDateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss+00:00", CultureInfo.InvariantCulture));

            var request = new CompositeSubRequest
            {
                Method      = "GET",
                ReferenceId = referenceId,
                Url         = $"sobjects/{objectName}/updated/?start={sdt}&end={edt}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
        public CompositeSubRequest BasicInformation(string referenceId, string objectName)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }

            var request = new CompositeSubRequest
            {
                Method      = "GET",
                ReferenceId = referenceId,
                Url         = $"sobjects/{objectName}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
Ejemplo n.º 14
0
        public CompositeSubRequest Explain(string referenceId, string query)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentNullException(nameof(query));
            }

            var request = new CompositeSubRequest
            {
                Method      = "GET",
                ReferenceId = referenceId,
                Url         = $@"query?explain={Dnf.EscapeDataString(query)}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
Ejemplo n.º 15
0
        public CompositeSubRequest QueryAll(string referenceId, string query)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentNullException(nameof(query));
            }

            var request = new CompositeSubRequest
            {
                ResponseType = "query",
                Method       = "GET",
                ReferenceId  = referenceId,
                Url          = $"queryAll?q={Uri.EscapeDataString(query)}"
            };

            CompositeRequests.Add(request);
            return(request);
        }
Ejemplo n.º 16
0
        public IList <CompositeSubRequest> Create <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      = "POST",
                    ReferenceId = $"{referenceId}_{chunkIdx}",
                    Url         = "composite/sobjects"
                };
                CompositeRequests.Add(request);
                result.Add(request);
            }
            return(result);
        }