Can anyone please tell me that how to get the ID of Custom Object like, I am loading all the Custom Object by describeglobal() and than setting the name, label and plural label as the datasource for a gridview.

Now I want ID of that particular custom object on click in GridView. My code is this ::

            DataTable table = new DataTable();
        table.Columns.Add("Name", typeof(string));
        table.Columns.Add("Label", typeof(string));
        table.Columns.Add("labelPlural", typeof(string));

        SforceService binding = (SforceService)Session["myobject"];

        DescribeGlobalResult dgr = binding.describeGlobal();
        DescribeSObjectResult[] dsrArray;

        for (int i = 0; i < dgr.sobjects.Length; i++)
            //DescribeSObjectResult[] arr = new  DescribeSObjectResult[500];
            if (dgr.sobjects[i].name.Contains("__c"))
                dsrArray = binding.describeSObjects(new string[] { dgr.sobjects[i].name });

                for (int j = 0; j < dsrArray.Length; j++)
                    string Name = dsrArray[j].name;
                    string Label = dsrArray[j].label;
                    string Plural_Label = dsrArray[j].labelPlural;
                    table.Rows.Add(Name, Label, Plural_Label);

        grdObjects.DataSource = table;

I am setting the label as linkbutton in the gridview

Regards Raman


When you use reflection to get information about objects, you are actually getting information about object types, not object instances.

Object types are like templates (classes) for creating actual instances. Only object instances have properties like IDs or values of other fields. Therefore you cannot find an ID of an object type.

Instance vs type

DescribeSObjectResult contains only information on the object type and information on its fields in the sense of how those field look like as a prototype from which an actual object is built. In other words, what is the field itself and not what information the field contains in some object instance.

For example, you can get information on whether the field is calculated, what is the field's label, whether the field will be autonumbered, if the field should be unique and so on, as documented on DescribeSObjectResult page.

  • humnnnnnnn !!! Means This is the thing, thanks ipavlic – Raman Jun 5 '13 at 10:45
  • What the OP means is the reverse of this or the same as this unsolved question – JannieT Sep 26 '13 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.