public async Task <string> Create(SalesforceObjectType type, IDictionary <string, object> @object, AuthorizationToken authToken)
        {
            var result = await ExecuteClientOperationWithTokenRefresh(CreateForceClient, x => x.CreateAsync(type.ToString(), @object), authToken);

            return(result?.Id ?? string.Empty);
        }
        public async Task <List <FieldDTO> > GetProperties(SalesforceObjectType type, AuthorizationToken authToken, bool updatableOnly = false, string label = null)
        {
            var responce = (JObject) await ExecuteClientOperationWithTokenRefresh(CreateForceClient, x => x.DescribeAsync <object>(type.ToString()), authToken);

            var    objectFields = new List <FieldDTO>();
            JToken resultFields;

            if (responce.TryGetValue("fields", out resultFields) && resultFields is JArray)
            {
                if (updatableOnly)
                {
                    resultFields = new JArray(resultFields.Where(fieldDescription => fieldDescription.Value <bool>("updateable")));
                }

                var fields = resultFields
                             .Select(fieldDescription =>

                                     /*
                                      * Select Fields as FieldDTOs with
                                      *
                                      * Key -> Field Name
                                      * Value -> Field Lable
                                      * AvailabilityType -> Run Time
                                      * FieldType -> Field Type
                                      *
                                      * IsRequired -> The Field is required when ALL the below conditions are true.
                                      *  nillable            = false, Meaning, the field must have a valid value. The field's value should not be NULL or NILL or Empty
                                      *  defaultedOnCreate   = false, Meaning, Salesforce itself does not assign default value for this field when object is created (ex. ID)
                                      *  updateable          = true,  Meaning, The filed's value must be updatable by the user.
                                      *                                      User must be able to set or modify the value of this field.
                                      */
                                     new FieldDTO(fieldDescription.Value <string>("name"))
                {
                    FieldType = ExtractFieldType(fieldDescription.Value <string>("type")),

                    IsRequired = fieldDescription.Value <bool>("nillable") == false &&
                                 fieldDescription.Value <bool>("defaultedOnCreate") == false &&
                                 fieldDescription.Value <bool>("updateable") == true,
                    Availability     = AvailabilityType.RunTime,
                    Label            = fieldDescription.Value <string>("label"),
                    Data             = ExtractFieldData(fieldDescription.ToObject <JObject>()),
                    SourceCrateLabel = label
                }
                                     )
                             .OrderBy(field => field.Name);

                objectFields.AddRange(fields);
            }
            else
            {
                var errorMessage = "Request to Salesforce object properties returned unexpected results";
                _logger.Error(errorMessage);
                throw new ApplicationException(errorMessage);
            }
            return(objectFields);
        }
 public async Task <bool> Delete(SalesforceObjectType objectType, string objectId, AuthorizationToken authToken)
 {
     try
     {
         return(await ExecuteClientOperationWithTokenRefresh(CreateForceClient, x => x.DeleteAsync(objectType.ToString(), objectId), authToken));
     }
     catch (ForceException ex)
     {
         _logger.Error($"Failed to delete {objectType} with Id {objectId}", ex);
         throw;
     }
 }