+ Start a Discussion
Dheeraj ChawlaDheeraj Chawla 

can anyone explain these code lines in a simple English...?

String objType=’Account’;
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(objType);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();


 
Best Answer chosen by Dheeraj Chawla
Himanshu ParasharHimanshu Parashar
Schema Class is used to get metadata details of any object in Salesforce so in simple words suppose you have a MQSQL database and you have a table called Account and you want to get all the fields of that table in code you will write some php code right? 

Salesforce provides some predefined method which takes some parameter and return specific information
 
String objType=’Account’; // Object name for which we are looking for data

//get All the object details and store them in a map where object name is a key
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); 

//get Account oject data by passing 'Account' using .get method of Map
Schema.SObjectType leadSchema = schemaMap.get(objType);

//Get all the object fields using Schema.getDescribe.fields.getMap method.
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();

At the end your fieldMap will contain all the fields detail of Account object. which will include data type (text, number,checkbox, email id) data type length, isRequired, label of field etc

Makes sense?

Thanks,
Himanshu