Get all the fields of sObject dynamically salesforce?

String qid = 'a0A2800000HVQSc';
String objectName = 'Employees__c';
List<String> objFields =  new List<String>();
Map<String,Schema.SObjectType> schemaGlobalDescription = Schema.getGlobalDescribe();
Schema.sObjectType objType = schemaGlobalDescription.get(objectName);
Schema.DescribeSObjectResult objDescribeSObjectResult = objType.getDescribe();
Map<String,Schema.SObjectField> mapFieldList = objDescribeSObjectResult.fields.getMap();
String commaSepratedFields ='';
for(Schema.SObjectField field : mapFieldList.values()){
    Schema.DescribeFieldResult fieldResult = field.getDescribe();
        commaSepratedFields += fieldResult.getName()+',';
}
commaSepratedFields = commaSepratedFields.substring(0,commaSepratedFields.length()-1);
String query = 'select ' + commaSepratedFields + ' from Employees__c Limit 1';
system.debug(query);
list<Employees__c> listEMP = database.query(query);
system.debug(listEMP);

No comments:

Featured

What is Cryptography in salesforce and what are all the algorithms provided by them ?

A). It is a security protocal between two systems. Lets say we are integration two systems without any encrytion mechanism then hackers wil...

Popular