I'm facing with the current problem. I have the following code which is a list of SObject and I want to get "CreatedDate" field. I really appreciate ur time and comments, thanks.
public static Object testMeth() {
List<SObject> leadsAndOpps = new List<SObject>();
List<Lead> lstLead = [Select Id, Name, CreatedDate FROM Lead];
List<Opportunity> lstOpp = [Select Id, Name, CreatedDate FROM Opportunity];
//Assign first and second List to Sobject List
leadsAndOpps.addAll(lstLead);
leadsAndOpps.addAll(lstOpp);
for(SObject lstExa : leadsAndOpps) {
String getName = (String)lstExa.get('Name'); = This example works cool
DateTime getDateVal = (DateTime)lstExa.get(CreatedDate); = Variable doesn't exists
}
return leadsAndOpps;
}