You need to sign in to do that
Don't have an account?
Guru 91
Apex controller test class
--------I am not getting how to write a test calss for this apex controller?
public class OV_ObjectUtility {
public static void getData(){
List<String> ids = new List<String>();
ids.add('001U0000004ZjhgIAC');
ids.add('0010B00001lL1VEQA0');
ids.add('001e0000018SOK5AAO');
ids.add('001e0000018SOKAAA4');
lightningTableWrapper ffff= getRecordsForSearch('Account','Name, OriginalAccountName__c, TradestyleName__c, Continent__c, BillingCity, BillingCountry, website, BillingPostalCode, BillingState, BillingStreet, Id',ids);
system.debug('----Final Query Datas ---'+ffff);
}
public static lightningTableWrapper getRecordsForSearch(String ObjectName,String fieldstoget,List<String> ids){
lightningTableWrapper ltw = new lightningTableWrapper();
String wherecon='';
try{
for(String str : ids){
if(str!=null){
wherecon = wherecon+ ' \''+str + '\',' ;
}
}
wherecon = wherecon.subString(0,wherecon.length()-1);
String queryString = 'Select '+ String.escapeSingleQuotes(fieldstoget)+
' from '+ String.escapeSingleQuotes(ObjectName)+
' where id in ('+wherecon+')';
system.debug('----Final Query---'+queryString);
List<sobject> sObjectsList = new List<sobject>();
sObjectsList.addAll(database.query(queryString));
system.debug('----Final Query Datas ---'+sObjectsList);
ltw.sObjectrecords = sObjectsList;
}catch(Exception e){
}
return ltw;
}
}
public class OV_ObjectUtility {
public static void getData(){
List<String> ids = new List<String>();
ids.add('001U0000004ZjhgIAC');
ids.add('0010B00001lL1VEQA0');
ids.add('001e0000018SOK5AAO');
ids.add('001e0000018SOKAAA4');
lightningTableWrapper ffff= getRecordsForSearch('Account','Name, OriginalAccountName__c, TradestyleName__c, Continent__c, BillingCity, BillingCountry, website, BillingPostalCode, BillingState, BillingStreet, Id',ids);
system.debug('----Final Query Datas ---'+ffff);
}
public static lightningTableWrapper getRecordsForSearch(String ObjectName,String fieldstoget,List<String> ids){
lightningTableWrapper ltw = new lightningTableWrapper();
String wherecon='';
try{
for(String str : ids){
if(str!=null){
wherecon = wherecon+ ' \''+str + '\',' ;
}
}
wherecon = wherecon.subString(0,wherecon.length()-1);
String queryString = 'Select '+ String.escapeSingleQuotes(fieldstoget)+
' from '+ String.escapeSingleQuotes(ObjectName)+
' where id in ('+wherecon+')';
system.debug('----Final Query---'+queryString);
List<sobject> sObjectsList = new List<sobject>();
sObjectsList.addAll(database.query(queryString));
system.debug('----Final Query Datas ---'+sObjectsList);
ltw.sObjectrecords = sObjectsList;
}catch(Exception e){
}
return ltw;
}
}
Do not use Hard code is in your apex class.
After removing hard code ids try this way out for reaching your code coverage.
Try this way out for your Test class code --
Thanks
Akshay
All Answers
There are many way to create test class for apex.
Please refer follow link
https://trailhead.salesforce.com/en/modules/apex_testing/units/apex_testing_intro
If any other question then you can post it,
Regards,
Pritesh
Do not use Hard code is in your apex class.
After removing hard code ids try this way out for reaching your code coverage.
Try this way out for your Test class code --
Thanks
Akshay