You need to sign in to do that
Don't have an account?
divya1234
need help for the test class
global class Edgeforce {
global class searchResult
{
string thumbnail = '';
string title = '';
string description = '';
string link = '';
integer size = 0;
string type = '';
id recordId;
sObject objectData;
String startDate = '';
}
//By this field Tab would be selected on intranetPages
global static String tabName {get; set;}
//This map is used to identified top level parent of CMS pages.
global static map<String, String> parentTabMap {get;set;}
//By this field category limit will be decided on each object.
global static final Integer categoryLimit {get;set;}
//By this field no of records will be decided to show on Search page
global static final Integer paginationLimit {get; set;}
//Key prefix of Intranet_Article__c object
private static final String IntranetArticleKeyPrefix {get; set;}
static Map<String, String> contentNameTitleMap;
static Map<String, String> parentTabNameMap;
static Map<SObject, Intranet_Content__c> versionContentMap = new Map<SObject, Intranet_Content__c>();
static {
//Initialize final varibles to decide search configuration
for(Intranet_content__c searchConfig : [Select Name, value__c From Intranet_content__c where recordType.Name = 'Config - Portal']) {
if(searchConfig.Name == 'Search Limit') {
categoryLimit = Integer.valueOf(searchConfig.value__c);
}
if(searchConfig.Name == 'Search Pagination') {
paginationLimit = Integer.valueOf(searchConfig.value__c);
}
}
IntranetArticleKeyPrefix = Schema.getGlobalDescribe().get('Intranet_Content_Version__c').getDescribe().getKeyPrefix();
}
/*remote method to be accessed via javascript for performing a search.
arguments
searchTerm: a string at least two characters long (not including wildcards) to search for
objectList: a list/array of sObject names which to query for
objectLabels: a map/javascript object of sObject names to a friendly label to use in the result. Multiple sObjects can have the same label and will be returned in the same group.
typeLimit: a maxmimum amount of each kind of object to find. This is per sObject type, not per label or for the total search.
*/
@RemoteAction
global static map<string,list<searchResult>> globalSearch(string searchTerm,boolean isMobile,list<string>objectList,map<string,string> objectLabels, integer typeLimit)
{
//map to hold the results. The results will have the objectLabels or names (if no label for that object type is provided) and a list of search results for it.
map<string,list<searchResult>> results = new map<string,list<searchResult>>();
map<String, boolean> isIncludedInSearchMap = new map<String,Boolean>();
parentTabMap = new map<String,String>();
try
{
string customObjectQuery = '';
objectLabels = new map<string,string>();
for(Intranet_Content__c searchConfig : [Select name,Object_Name__c,Display_In_Search__c From Intranet_Content__c Where RecordType.Name='Config - Search']) {
isIncludedInSearchMap.put(searchConfig.Object_Name__c, searchConfig.Display_In_Search__c);
objectLabels.put(searchConfig.Object_Name__c, searchConfig.Name);
}
String userLang = '';
for(Intranet_content__c searchConfig : [Select Name, value__c From Intranet_content__c where recordType.Name = 'Config - Portal' AND name =: userinfo.getLanguage()]){
if(searchConfig != null){
userLang = searchConfig.Value__c;
}
}
for(string obj : objectList)
{
if(obj == 'Intranet_Content_Version__c' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += 'Intranet_Content_Version__c' +'(Name,Id,Language__c,Intranet_Content__c,Summary__c WHERE isPublished__c = true order by LastModifiedDate DESC LIMIT '+typeLimit+'),';
}/*else if(obj == 'Intranet_CMS_Page__c' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += 'Intranet_Content_Version__c'+'(Name,Id,Intranet_Content__c,Intranet_Content__r.Template__c,Intranet_Content__r.Skip_Menu_Link__c,Intranet_Content__r.URL__c,Intranet_Content__r.createdById,Intranet_Content__r.CreatedDate WHERE Intranet_Content__r.Status__c = \'Published\' AND Intranet_Content__r.RecordType.Name = \'Intranet CMS Pages\' order by Name LIMIT '+typeLimit+'),';
}*/else if(obj == 'FeedItem' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += obj+'(id, title, body, InsertedBy.Name, InsertedById, CreatedDate, ParentId order by CreatedDate DESC LIMIT '+typeLimit+'),';
}else if(obj == 'ContentVersion' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += obj+'(ContentDocumentId,ContentSize,ContentUrl,Description,IsLatest,PublishStatus,TagCsv,Title,FileType,Id order by RatingCount DESC LIMIT '+typeLimit+'),';
}else if(obj == 'User' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += obj+'(id, name, SmallPhotoUrl, email order by Name LIMIT '+typeLimit+'),';
}else if(isIncludedInSearchMap.get(obj) == true){
customObjectQuery += obj+'(Name,Id,createdById,CreatedDate LIMIT '+typeLimit+'),';
}
}
system.debug(customObjectQuery);
string objectsQuery = 'FIND \''+searchTerm+'\' IN ALL FIELDS RETURNING '+customObjectQuery.subString(0, customObjectQuery.length()-1);
System.debug('debug objectsQuery >> ' + objectsQuery);
List<List<SObject>> tempSearchList = search.query(objectsQuery);
string objType = '';
string objLabel = '';
Map<ID,SObject> contentVersionMap;
List<List<SObject>> searchList = new List<List<SObject>>();
List<SObject> sobjList;
Set<ID> contentIdSet;
boolean isContent;
Map<ID, List<Intranet_Content_Version__c>> mapContContVersion;
for(List<sObject> thisObjList : tempSearchList){
sobjList= new List<SObject>();
contentVersionMap = new Map<ID, SObject>();
contentIdSet = new Set<ID>();
mapContContVersion = new Map<ID, List<Intranet_Content_Version__c>>();
isContent = false;
for(sObject thisObj : thisObjList){
if(string.valueOf(thisObj.getsObjectType()) == 'Intranet_Content_Version__c'){
isContent = true;
//Added by Sidhant Agarwal T-331988
if(!mapContContVersion.containsKey((string)thisObj.get('Intranet_Content__c'))) {
mapContContVersion.put((string)thisObj.get('Intranet_Content__c'), new List<Intranet_Content_Version__c>());
}
mapContContVersion.get((string)thisObj.get('Intranet_Content__c')).add((Intranet_Content_Version__c)thisObj);
}else{
sobjList.add(thisObj);
}
}
if(isContent){
for(String contentId : mapContContVersion.keyset()){
for(Intranet_Content_Version__c icv : mapContContVersion.get(contentId)){
sobjList.add(icv);
}
}
}
searchList.add(sobjList);
}
global class searchResult
{
string thumbnail = '';
string title = '';
string description = '';
string link = '';
integer size = 0;
string type = '';
id recordId;
sObject objectData;
String startDate = '';
}
//By this field Tab would be selected on intranetPages
global static String tabName {get; set;}
//This map is used to identified top level parent of CMS pages.
global static map<String, String> parentTabMap {get;set;}
//By this field category limit will be decided on each object.
global static final Integer categoryLimit {get;set;}
//By this field no of records will be decided to show on Search page
global static final Integer paginationLimit {get; set;}
//Key prefix of Intranet_Article__c object
private static final String IntranetArticleKeyPrefix {get; set;}
static Map<String, String> contentNameTitleMap;
static Map<String, String> parentTabNameMap;
static Map<SObject, Intranet_Content__c> versionContentMap = new Map<SObject, Intranet_Content__c>();
static {
//Initialize final varibles to decide search configuration
for(Intranet_content__c searchConfig : [Select Name, value__c From Intranet_content__c where recordType.Name = 'Config - Portal']) {
if(searchConfig.Name == 'Search Limit') {
categoryLimit = Integer.valueOf(searchConfig.value__c);
}
if(searchConfig.Name == 'Search Pagination') {
paginationLimit = Integer.valueOf(searchConfig.value__c);
}
}
IntranetArticleKeyPrefix = Schema.getGlobalDescribe().get('Intranet_Content_Version__c').getDescribe().getKeyPrefix();
}
/*remote method to be accessed via javascript for performing a search.
arguments
searchTerm: a string at least two characters long (not including wildcards) to search for
objectList: a list/array of sObject names which to query for
objectLabels: a map/javascript object of sObject names to a friendly label to use in the result. Multiple sObjects can have the same label and will be returned in the same group.
typeLimit: a maxmimum amount of each kind of object to find. This is per sObject type, not per label or for the total search.
*/
@RemoteAction
global static map<string,list<searchResult>> globalSearch(string searchTerm,boolean isMobile,list<string>objectList,map<string,string> objectLabels, integer typeLimit)
{
//map to hold the results. The results will have the objectLabels or names (if no label for that object type is provided) and a list of search results for it.
map<string,list<searchResult>> results = new map<string,list<searchResult>>();
map<String, boolean> isIncludedInSearchMap = new map<String,Boolean>();
parentTabMap = new map<String,String>();
try
{
string customObjectQuery = '';
objectLabels = new map<string,string>();
for(Intranet_Content__c searchConfig : [Select name,Object_Name__c,Display_In_Search__c From Intranet_Content__c Where RecordType.Name='Config - Search']) {
isIncludedInSearchMap.put(searchConfig.Object_Name__c, searchConfig.Display_In_Search__c);
objectLabels.put(searchConfig.Object_Name__c, searchConfig.Name);
}
String userLang = '';
for(Intranet_content__c searchConfig : [Select Name, value__c From Intranet_content__c where recordType.Name = 'Config - Portal' AND name =: userinfo.getLanguage()]){
if(searchConfig != null){
userLang = searchConfig.Value__c;
}
}
for(string obj : objectList)
{
if(obj == 'Intranet_Content_Version__c' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += 'Intranet_Content_Version__c' +'(Name,Id,Language__c,Intranet_Content__c,Summary__c WHERE isPublished__c = true order by LastModifiedDate DESC LIMIT '+typeLimit+'),';
}/*else if(obj == 'Intranet_CMS_Page__c' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += 'Intranet_Content_Version__c'+'(Name,Id,Intranet_Content__c,Intranet_Content__r.Template__c,Intranet_Content__r.Skip_Menu_Link__c,Intranet_Content__r.URL__c,Intranet_Content__r.createdById,Intranet_Content__r.CreatedDate WHERE Intranet_Content__r.Status__c = \'Published\' AND Intranet_Content__r.RecordType.Name = \'Intranet CMS Pages\' order by Name LIMIT '+typeLimit+'),';
}*/else if(obj == 'FeedItem' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += obj+'(id, title, body, InsertedBy.Name, InsertedById, CreatedDate, ParentId order by CreatedDate DESC LIMIT '+typeLimit+'),';
}else if(obj == 'ContentVersion' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += obj+'(ContentDocumentId,ContentSize,ContentUrl,Description,IsLatest,PublishStatus,TagCsv,Title,FileType,Id order by RatingCount DESC LIMIT '+typeLimit+'),';
}else if(obj == 'User' && isIncludedInSearchMap.get(obj) == true) {
customObjectQuery += obj+'(id, name, SmallPhotoUrl, email order by Name LIMIT '+typeLimit+'),';
}else if(isIncludedInSearchMap.get(obj) == true){
customObjectQuery += obj+'(Name,Id,createdById,CreatedDate LIMIT '+typeLimit+'),';
}
}
system.debug(customObjectQuery);
string objectsQuery = 'FIND \''+searchTerm+'\' IN ALL FIELDS RETURNING '+customObjectQuery.subString(0, customObjectQuery.length()-1);
System.debug('debug objectsQuery >> ' + objectsQuery);
List<List<SObject>> tempSearchList = search.query(objectsQuery);
string objType = '';
string objLabel = '';
Map<ID,SObject> contentVersionMap;
List<List<SObject>> searchList = new List<List<SObject>>();
List<SObject> sobjList;
Set<ID> contentIdSet;
boolean isContent;
Map<ID, List<Intranet_Content_Version__c>> mapContContVersion;
for(List<sObject> thisObjList : tempSearchList){
sobjList= new List<SObject>();
contentVersionMap = new Map<ID, SObject>();
contentIdSet = new Set<ID>();
mapContContVersion = new Map<ID, List<Intranet_Content_Version__c>>();
isContent = false;
for(sObject thisObj : thisObjList){
if(string.valueOf(thisObj.getsObjectType()) == 'Intranet_Content_Version__c'){
isContent = true;
//Added by Sidhant Agarwal T-331988
if(!mapContContVersion.containsKey((string)thisObj.get('Intranet_Content__c'))) {
mapContContVersion.put((string)thisObj.get('Intranet_Content__c'), new List<Intranet_Content_Version__c>());
}
mapContContVersion.get((string)thisObj.get('Intranet_Content__c')).add((Intranet_Content_Version__c)thisObj);
}else{
sobjList.add(thisObj);
}
}
if(isContent){
for(String contentId : mapContContVersion.keyset()){
for(Intranet_Content_Version__c icv : mapContContVersion.get(contentId)){
sobjList.add(icv);
}
}
}
searchList.add(sobjList);
}
As per your apex class your test class does not call globalSearch method.
Thanks,
Shailesh Rawte
globalSearch(string searchTerm,boolean isMobile,list<string>objectList,map<string,string> objectLabels, integer typeLimit)