Created
December 6, 2015 04:48
-
-
Save karanrajs/08eae1e3387dafffe2b3 to your computer and use it in GitHub Desktop.
Apex class to get recently viewed records
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
public class RecentRecordsController { | |
@AuraEnabled public static List<sobject> getRecentRecords(String ObjectName,String limits,String fieldstoget){ | |
List<Id> recentlyViewedIds = new List<Id>(); | |
Integer limitofRecord = Integer.valueOf(String.escapeSingleQuotes(limits)); | |
for(sObject obj : [Select Id from RecentlyViewed where Type =:String.escapeSingleQuotes(ObjectName)]){ | |
recentlyViewedIds.add(obj.Id); | |
} | |
String queryString = 'Select '+ String.escapeSingleQuotes(fieldsToGet)+ | |
' from '+ String.escapeSingleQuotes(ObjectName) + | |
' where ID IN:recentlyViewedIds Limit '+ limitofRecord; | |
return database.query(queryString); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment