Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sunil02kumar/1f74113192b82d094175e67c560acbd1 to your computer and use it in GitHub Desktop.
Save Sunil02kumar/1f74113192b82d094175e67c560acbd1 to your computer and use it in GitHub Desktop.
String objectName = 'Lead';
Schema.SObjectType objToken = Schema.getGlobalDescribe().get(objectName);
//find details about sobject
Schema.DescribeSObjectResult objDescribe=objToken.getdescribe();
system.debug('*********sobjectAPINamel:'+objDescribe.getName());
//finding all fields of Lead and generating query dynamically
Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
String query = 'Select ';
string conid='00Qxxxxxxxxxx'; //you can hard code the LeadId or you can pass it through apex method
for(String ss:Fieldmap.keyset()){
Schema.DescribeFieldResult fd=fieldMap.get(ss).getDescribe();
system.debug('*********fieldAPINamel:'+fd.getName());
query = query + fd.getName() + ',';
}
query = query.subString(0,query.length() - 1);
query = query + ' from ';
query = query + objDescribe.getName();
query = query + ' where Id = \'';
query = query + conid + '\'';
system.debug('*********Lead Query: ' + query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment