private Field[] getFields(string entityType, string[] fields)
        {
            var describeSObjectResults = binding.describeSObjects(new string[] { entityType });

            if (fields.Length != 0)
            {
                var salesForceFields = new Field[fields.Length];
                var allFieldsInArray = describeSObjectResults[0].fields;
                var allFields        = new ArrayList();

                for (int i = 0; i < allFieldsInArray.Length; i++)
                {
                    allFields.Add(allFieldsInArray[i].name.ToLower());
                }

                int index = 0;

                for (int i = 0; i < fields.Length; i++)
                {
                    if (allFields.Contains(fields[i].ToLower()))
                    {
                        int fieldIndex = allFields.IndexOf(fields[i].ToLower());
                        salesForceFields[index] = allFieldsInArray[fieldIndex];
                        index++;
                    }
                }

                return(salesForceFields);
            }
            else
            {
                return(describeSObjectResults[0].fields);
            }
        }
Example #2
0
        private Field[] GetFields(string entityType, IReadOnlyCollection <string> fields)
        {
            var describeSObjectResults = binding.describeSObjects(new[] { entityType });

            if (fields.Count != 0)
            {
                var salesForceFields = new Field[fields.Count];
                var allFieldsInArray = describeSObjectResults[0].fields;
                var allFields        = new ArrayList();

                foreach (var field in allFieldsInArray)
                {
                    allFields.Add(field.name.ToLower());
                }

                var index = 0;

                foreach (var fieldIndex in from field in fields where allFields.Contains(field.ToLower()) select allFields.IndexOf(field.ToLower()))
                {
                    salesForceFields[index] = allFieldsInArray[fieldIndex];
                    index++;
                }

                return(salesForceFields);
            }
            else
            {
                return(describeSObjectResults[0].fields);
            }
        }
Example #3
0
        public IEnumerable <DescribeSObjectResult> GetSObjectDetails(List <string> tableNames)
        {
            ConcurrentBag <DescribeSObjectResult> results = new ConcurrentBag <DescribeSObjectResult>();

            Parallel.ForEach(splitList(tableNames, 100), (tableSet) => {
                foreach (DescribeSObjectResult o in salesforceSoapService.describeSObjects(tableSet.ToArray()))
                {
                    results.Add(o);
                }
            });
            return(results);
        }
Example #4
0
        public void FetchObjectMetadata(string[] apiNameArray)
        {
            LoginIfRequired();
            logger.DebugFormat("Fetching metadata for {0} object types", apiNameArray.Length);
            var metaList = _binding.describeSObjects(apiNameArray);

            foreach (var metaLoop in metaList)
            {
                if (!_metaDictionary.ContainsKey(metaLoop.name))
                {
                    _metaDictionary.Add(metaLoop.name, metaLoop);
                }
            }
        }
Example #5
0
        public PicklistEntry[] GetLeadSourcePicklist()
        {
            SforceService SfdcBinding = SalesForceSession();

            PicklistEntry[]         picklistValues         = null;
            DescribeSObjectResult[] describeSObjectResults = SfdcBinding.describeSObjects(new string[] { "lead" });
            Field[] fields = describeSObjectResults[0].fields;
            foreach (Field field in fields)
            {
                if (field.type == fieldType.picklist && field.name == "Status")
                {
                    picklistValues = field.picklistValues;
                    break;
                }
            }

            return(picklistValues);
        }
Example #6
0
        /// <summary>
        /// Retruns table definitions from salesforce for sent in tables
        /// </summary>
        /// <param name="tableNames">A list of table names you would like information about</param>
        /// <returns></returns>
        public List <TableInfo> DescribeTables(string[] tableNames)
        {
            DescribeSObjectResult[] dsrArray = binding.describeSObjects(tableNames.Take(50).ToArray()); // get everything as this project grows we will need more from this
            var results = dsrArray.Select(c => new TableInfo
            {
                name   = c.name,
                label  = c.label,
                fields = c.fields?.Select(x => new FieldInformation
                {
                    label = x.label,
                    name  = x.name,
                    type  = x.type.ToString()
                }).ToList(),
                relationships = c.childRelationships?.Select(x => new RelationshipInformation
                {
                    ChildTable = x.childSObject,
                    ChildField = x.field
                }).ToList()
            }).ToList();

            return(results);
        }
Example #7
0
        /**
         * The following method illustrates the type of metadata
         * information that can be obtained for each object available
         * to the user. The sample client application executes a
         * describeSObject call on a given object and then echoes
         * the returned metadata information to the console. Object
         * metadata information includes permissions, field types
         * and length and available values for picklist fields
         * and types for referenceTo fields.
         */
        private void describeSObjectsSample()
        {
            Console.Write("\nType the name of the object to " +
                          "describe (try Account): ");
            string objectType = Console.ReadLine();

            try
            {
                // Call describeSObjects() passing in an array with one object type name
                DescribeSObjectResult[] dsrArray =
                    binding.describeSObjects(new string[] { objectType });

                // Since we described only one sObject, we should have only
                // one element in the DescribeSObjectResult array.
                DescribeSObjectResult dsr = dsrArray[0];

                // First, get some object properties
                Console.WriteLine("\n\nObject Name: " + dsr.name);

                if (dsr.custom)
                {
                    Console.WriteLine("Custom Object");
                }
                if (dsr.label != null)
                {
                    Console.WriteLine("Label: " + dsr.label);
                }

                // Get the permissions on the object
                if (dsr.createable)
                {
                    Console.WriteLine("Createable");
                }
                if (dsr.deletable)
                {
                    Console.WriteLine("Deleteable");
                }
                if (dsr.queryable)
                {
                    Console.WriteLine("Queryable");
                }
                if (dsr.replicateable)
                {
                    Console.WriteLine("Replicateable");
                }
                if (dsr.retrieveable)
                {
                    Console.WriteLine("Retrieveable");
                }
                if (dsr.searchable)
                {
                    Console.WriteLine("Searchable");
                }
                if (dsr.undeletable)
                {
                    Console.WriteLine("Undeleteable");
                }
                if (dsr.updateable)
                {
                    Console.WriteLine("Updateable");
                }

                Console.WriteLine("Number of fields: " + dsr.fields.Length);

                // Now, retrieve metadata for each field
                for (int i = 0; i < dsr.fields.Length; i++)
                {
                    // Get the field
                    Field field = dsr.fields[i];

                    // Write some field properties
                    Console.WriteLine("Field name: " + field.name);
                    Console.WriteLine("\tField Label: " + field.label);

                    // This next property indicates that this
                    // field is searched when using
                    // the name search group in SOSL
                    if (field.nameField)
                    {
                        Console.WriteLine("\tThis is a name field.");
                    }

                    if (field.restrictedPicklist)
                    {
                        Console.WriteLine("This is a RESTRICTED picklist field.");
                    }

                    Console.WriteLine("\tType is: " + field.type.ToString());

                    if (field.length > 0)
                    {
                        Console.WriteLine("\tLength: " + field.length);
                    }

                    if (field.scale > 0)
                    {
                        Console.WriteLine("\tScale: " + field.scale);
                    }

                    if (field.precision > 0)
                    {
                        Console.WriteLine("\tPrecision: " + field.precision);
                    }

                    if (field.digits > 0)
                    {
                        Console.WriteLine("\tDigits: " + field.digits);
                    }

                    if (field.custom)
                    {
                        Console.WriteLine("\tThis is a custom field.");
                    }

                    // Write the permissions of this field
                    if (field.nillable)
                    {
                        Console.WriteLine("\tCan be nulled.");
                    }
                    if (field.createable)
                    {
                        Console.WriteLine("\tCreateable");
                    }
                    if (field.filterable)
                    {
                        Console.WriteLine("\tFilterable");
                    }
                    if (field.updateable)
                    {
                        Console.WriteLine("\tUpdateable");
                    }

                    // If this is a picklist field, show the picklist values
                    if (field.type.Equals(fieldType.picklist))
                    {
                        Console.WriteLine("\tPicklist Values");
                        for (int j = 0; j < field.picklistValues.Length; j++)
                        {
                            Console.WriteLine("\t\t" + field.picklistValues[j].value);
                        }
                    }

                    // If this is a foreign key field (reference),
                    // show the values
                    if (field.type.Equals(fieldType.reference))
                    {
                        Console.WriteLine("\tCan reference these objects:");
                        for (int j = 0; j < field.referenceTo.Length; j++)
                        {
                            Console.WriteLine("\t\t" + field.referenceTo[j]);
                        }
                    }
                    Console.WriteLine("");
                }
            }
            catch (SoapException e)
            {
                Console.WriteLine("An exception has occurred: " + e.Message +
                                  "\nStack trace: " + e.StackTrace);
            }
            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();
        }