Created
September 13, 2016 10:24
-
-
Save Sunil02kumar/1f74113192b82d094175e67c560acbd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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