function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to get the field type in runtime.

In runtime composed querry, that get result as List<sObject> when sObject type is specified also in runtime.


After this i need to make same manipulation with data that contains in that's sObject fields. So i need to get type for each of them.


I use part of code like this


List<sObject> QuerryResult = Database.querry(....); 

Schema.DescribeSObjectResult ObjDescribe = QuerryResult[0].getSObjectType().getDescribe();

Schema.DescribeFieldResult FieldDescribe =  ObjDescribe.fields.*Name Of Field*.getDescribe();

Schema.SOAPType FieldType = FieldDescribe.getSOAPType();

 So the first question is: How can i get the field from fields array, when FieldName contains in another string variable and I don't know it when write code, just in runtime. (mb smth like $ in php or Type.getType(string typeName) in C#)


And the second(closely wired with the first): How can i get Schema.DescribeSObjectResult when name of object contains in another string variable. Becouse make querry before getting  all info about recieving fields crossing with understandible of program.


Smth like this:


Schema.DescribeSObjectResult ObjDescribe = Schema.SObjectType.*Name of sObject*







Best Answer chosen by Admin (Salesforce Developers) 

1. SObjectType.fields.getMap()

2. Schema.getGlobalDescribe()

All Answers


1. SObjectType.fields.getMap()

2. Schema.getGlobalDescribe()

This was selected as the best answer

Thanks, was realy tired to miss this funcs.