You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Test class for custom object Apex class
Hello, I need a test class for my apex class. I tried it but failed. Could you help me please?
public class MediathekSearchController2 { @AuraEnabled(cacheable=true) public static List<List<sObject>> getSearchResult(String searchKey, String TypValue, String ZielgruppeValue, String ThemaValue){ String findStr = searchKey+'*'; String AWhere111 = ' AND Typ__c = \''+ TypValue + '\''; Boolean isEmptySearch = String.isEmpty(searchKey); String findClause; system.debug('Das searchKey ist: ' + findStr); List <String> WhereClauses = new List <String>(); IF (searchKey !=null) { IF (ThemaValue !=null && ThemaValue !='Alle') { WhereClauses.Add('Thema__c = \'' + ThemaValue + '\''); } IF (TypValue !=null && TypValue !='Alle') { WhereClauses.Add('Typ__c = \'' + TypValue + '\''); } IF (ZielgruppeValue !=null && ZielgruppeValue !='Alle') { WhereClauses.Add('Zielgruppe__c = \'' + ZielgruppeValue + '\''); } } String WhereClause = String.join(WhereClauses, ' AND '); IF (WhereClauses.size()>0){ findClause = 'FIND \'' + findStr + '\' IN ALL FIELDS RETURNING Mediathek__c (Id, Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, ContentDocumentID__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c WHERE Inaktiv__c=false AND ' + WhereClause + ')'; }else{ findClause = 'FIND \'' + findStr + '\' IN ALL FIELDS RETURNING Mediathek__c (Id, Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, ContentDocumentID__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c WHERE Inaktiv__c=false)'; } system.debug('findcluase: ' +findclause); // String findClause = 'FIND\'' + findStr + '\' IN ALL FIELDS RETURNING Mediathek__c (Id, Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, ContentDocumentID__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c WHERE Inaktiv__c=false)'; // List <String> Find2 = new List <String>(findClause); List<List<sObject>> searchResult2 = search.query(findClause); system.debug('Das searchResult2 ist: ' + searchResult2); String SQL = searchResult2 + WhereClause; system.debug('Der Query ist: ' + SQL); return searchResult2; } @AuraEnabled public static Map<String, String> getTypFieldValue(){ Map<String, String> options = new Map<String, String>(); Schema.DescribeFieldResult fieldResult = Mediathek__c.Typ__c.getDescribe(); List<Schema.PicklistEntry> pValues = fieldResult.getPicklistValues(); for (Schema.PicklistEntry p: pValues) { options.put(p.getValue(), p.getLabel()); } return options; } @AuraEnabled public static Map<String, String> getThemaFieldValue(){ Map<String, String> options = new Map<String, String>(); Schema.DescribeFieldResult fieldResult = Mediathek__c.Thema__c.getDescribe(); List<Schema.PicklistEntry> pValues = fieldResult.getPicklistValues(); for (Schema.PicklistEntry p: pValues) { options.put(p.getValue(), p.getLabel()); } return options; } @AuraEnabled public static Map<String, String> getZielgruppeFieldValue(){ Map<String, String> options = new Map<String, String>(); Schema.DescribeFieldResult fieldResult = Mediathek__c.Zielgruppe__c.getDescribe(); List<Schema.PicklistEntry> pValues = fieldResult.getPicklistValues(); for (Schema.PicklistEntry p: pValues) { options.put(p.getValue(), p.getLabel()); } return options; } }
Please try with below test class and let me know further
If it helps please mark this as best answer
Thank you.