You need to sign in to do that
Don't have an account?
rmranjith8881.3927046400771116E12
Test class code coverage
public void dynamicSearch(){
try{
String searchingRecTypeName = 'Education Sponsor';
OpportunityRecordTypes__c edSponsorSearch = OpportunityRecordTypes__c.getValues('RT1');//object to get record type using custom settings
if(searchingRecTypeName == 'Education Sponsor'){
searchingRecTypeName = edSponsorSearch.RecordTypeName__c;
}
String selectStr =' Select Id, Name, Account.Id, Account.Name,Standard__c,Record_Type_Name__c,Student_Name__r.STD__c, StageName, Sponsorship_For__c, Std__c, Student_Name__c, Sponsorship_Date__c ' +
' FROM Opportunity WHERE Recordtype.name = :searchingRecTypeName ';
String whereStr ='';
String orderBy=' order by Std__c ASC limit 1000';
String whereStr1 = (con.STD__c != null) ? whereStr + ' Student_Name__r.STD__c = \''+ con.STD__c+'\'' : '';
String whereStr2 = (oppObj.Student_Name__c!=null) ? whereStr + ' Student_Name__c = \''+ oppObj.Student_Name__c+'\'' : '';
String whereStr3 = (oppObj.Sponsorship_For__c != null) ? whereStr + ' Sponsorship_For__c = \''+ oppObj.Sponsorship_For__c+'\'' : '';
String whereStr4 = (oppObj.Name !='') ? whereStr + ' Name Like \'%'+oppObj.Name+'%\' ' : '';
whereStr =(whereStr1.length()>0) ? whereStr + ' AND ' + whereStr1 : whereStr;
whereStr =(whereStr2.length()>0) ? whereStr + ' AND ' + whereStr2 : whereStr;
whereStr =(whereStr3.length()>0) ? whereStr + ' AND ' + whereStr3 : whereStr;
whereStr =(whereStr4.length()>0) ? whereStr + ' AND ' + whereStr4 : whereStr;
String qry = (selectStr + whereStr + orderBy);
oppList = Database.query(selectStr + whereStr + orderBy);
}catch(Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, e.getMessage()));
}
}
In the above dynamicSearch() method some of the code(iam displaying below) not covered.
String selectStr =' Select Id, Name, Account.Id, Account.Name,Standard__c,Record_Type_Name__c,Student_Name__r.STD__c, StageName, Sponsorship_For__c, Std__c, Student_Name__c, Sponsorship_Date__c ' +
' FROM Opportunity WHERE Recordtype.name = :searchingRecTypeName ';
String whereStr ='';
String orderBy=' order by Std__c ASC limit 1000';
String whereStr1 = (con.STD__c != null) ? whereStr + ' Student_Name__r.STD__c = \''+ con.STD__c+'\'' : '';
String whereStr2 = (oppObj.Student_Name__c!=null) ? whereStr + ' Student_Name__c = \''+ oppObj.Student_Name__c+'\'' : '';
String whereStr3 = (oppObj.Sponsorship_For__c != null) ? whereStr + ' Sponsorship_For__c = \''+ oppObj.Sponsorship_For__c+'\'' : '';
String whereStr4 = (oppObj.Name !='') ? whereStr + ' Name Like \'%'+oppObj.Name+'%\' ' : '';
whereStr =(whereStr1.length()>0) ? whereStr + ' AND ' + whereStr1 : whereStr;
whereStr =(whereStr2.length()>0) ? whereStr + ' AND ' + whereStr2 : whereStr;
whereStr =(whereStr3.length()>0) ? whereStr + ' AND ' + whereStr3 : whereStr;
whereStr =(whereStr4.length()>0) ? whereStr + ' AND ' + whereStr4 : whereStr;
String qry = (selectStr + whereStr + orderBy);
oppList = Database.query(selectStr + whereStr + orderBy);
can you tell me how can we cover the code for that.
Thanks in adance.
try{
String searchingRecTypeName = 'Education Sponsor';
OpportunityRecordTypes__c edSponsorSearch = OpportunityRecordTypes__c.getValues('RT1');//object to get record type using custom settings
if(searchingRecTypeName == 'Education Sponsor'){
searchingRecTypeName = edSponsorSearch.RecordTypeName__c;
}
String selectStr =' Select Id, Name, Account.Id, Account.Name,Standard__c,Record_Type_Name__c,Student_Name__r.STD__c, StageName, Sponsorship_For__c, Std__c, Student_Name__c, Sponsorship_Date__c ' +
' FROM Opportunity WHERE Recordtype.name = :searchingRecTypeName ';
String whereStr ='';
String orderBy=' order by Std__c ASC limit 1000';
String whereStr1 = (con.STD__c != null) ? whereStr + ' Student_Name__r.STD__c = \''+ con.STD__c+'\'' : '';
String whereStr2 = (oppObj.Student_Name__c!=null) ? whereStr + ' Student_Name__c = \''+ oppObj.Student_Name__c+'\'' : '';
String whereStr3 = (oppObj.Sponsorship_For__c != null) ? whereStr + ' Sponsorship_For__c = \''+ oppObj.Sponsorship_For__c+'\'' : '';
String whereStr4 = (oppObj.Name !='') ? whereStr + ' Name Like \'%'+oppObj.Name+'%\' ' : '';
whereStr =(whereStr1.length()>0) ? whereStr + ' AND ' + whereStr1 : whereStr;
whereStr =(whereStr2.length()>0) ? whereStr + ' AND ' + whereStr2 : whereStr;
whereStr =(whereStr3.length()>0) ? whereStr + ' AND ' + whereStr3 : whereStr;
whereStr =(whereStr4.length()>0) ? whereStr + ' AND ' + whereStr4 : whereStr;
String qry = (selectStr + whereStr + orderBy);
oppList = Database.query(selectStr + whereStr + orderBy);
}catch(Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, e.getMessage()));
}
}
In the above dynamicSearch() method some of the code(iam displaying below) not covered.
String selectStr =' Select Id, Name, Account.Id, Account.Name,Standard__c,Record_Type_Name__c,Student_Name__r.STD__c, StageName, Sponsorship_For__c, Std__c, Student_Name__c, Sponsorship_Date__c ' +
' FROM Opportunity WHERE Recordtype.name = :searchingRecTypeName ';
String whereStr ='';
String orderBy=' order by Std__c ASC limit 1000';
String whereStr1 = (con.STD__c != null) ? whereStr + ' Student_Name__r.STD__c = \''+ con.STD__c+'\'' : '';
String whereStr2 = (oppObj.Student_Name__c!=null) ? whereStr + ' Student_Name__c = \''+ oppObj.Student_Name__c+'\'' : '';
String whereStr3 = (oppObj.Sponsorship_For__c != null) ? whereStr + ' Sponsorship_For__c = \''+ oppObj.Sponsorship_For__c+'\'' : '';
String whereStr4 = (oppObj.Name !='') ? whereStr + ' Name Like \'%'+oppObj.Name+'%\' ' : '';
whereStr =(whereStr1.length()>0) ? whereStr + ' AND ' + whereStr1 : whereStr;
whereStr =(whereStr2.length()>0) ? whereStr + ' AND ' + whereStr2 : whereStr;
whereStr =(whereStr3.length()>0) ? whereStr + ' AND ' + whereStr3 : whereStr;
whereStr =(whereStr4.length()>0) ? whereStr + ' AND ' + whereStr4 : whereStr;
String qry = (selectStr + whereStr + orderBy);
oppList = Database.query(selectStr + whereStr + orderBy);
can you tell me how can we cover the code for that.
Thanks in adance.
here is my test class,
can you tell me how can we cover the code for that?
//Test class for StudentSponsorController
static testMethod void testStudentSponsorController(){
List<Opportunity> allOppotunityList = new List<Opportunity>();
String searchingRecTypeName;
Account acc = new Account(Name = 'Test Account');
insert acc;
Contact conTemp = new Contact();
conTemp.LastName = 'Test Contact';
conTemp.STD__c = '12';
insert conTemp;
Opportunity oppTemp = new Opportunity(Name = 'testOpp11');
oppTemp.AccountId = acc.Id;
oppTemp.name='menaka';
oppTemp.Student_Name__c = conTemp.Id;
oppTemp.Std__c='8';
oppTemp.Record_Type_Name__c='Education Sponsor';
oppTemp.CloseDate = System.today();
oppTemp.StageName = 'Closed Won';
oppTemp.Sponsorship_For__c='Education';
oppTemp.Sponsorship_Date__c=System.today()+2;
insert oppTemp;
allOppotunityList.add(oppTemp);
PageReference pg = page.StudentSponsorPage;
Test.setCurrentPage(pg);
ApexPages.CurrentPage().getParameters().put('Export','sfdc.tabName');
studentSponsorController stdntSC = new studentSponsorController();
stdntSC.sortDirection='ASC';
stdntSC.sortExp='ASC';
stdntSC.sortExpression=stdntSC.sortExp;
stdntSC.getSortDirection();
stdntSC.ViewData();
stdntSC.View();
stdntSC.getOppList();
stdntSC.reset();
stdntSC.dynamicSearch();
stdntSC.export();
Opportunity oppTemp1 = new Opportunity(Name = 'opptest2');
oppTemp1.AccountId = acc.Id;
oppTemp1.name='menaka';
oppTemp1.Student_Name__c = conTemp.Id;
oppTemp1.CloseDate = System.today()+3;
oppTemp1.StageName = 'Posted';
searchingRecTypeName ='Education Sponsor';
insert oppTemp1;
allOppotunityList.add(oppTemp1);
studentSponsorController stdntSC1 = new studentSponsorController();
stdntSC1.sortDirection='';
stdntSC1.sortExp='';
stdntSC1.sortExpression=stdntSC.sortExp;
stdntSC1.getSortDirection();
stdntSC1.ViewData();
stdntSC1.View();
stdntSC1.getOppList();
stdntSC1.reset();
oppTemp1.Record_Type_Name__c= '';
stdntSC1.dynamicSearch();
stdntSC1.export();
}
Thank you in addvance.
Can you tell me what was the problem behind this?
why am i not covered that part of code?
can yoou tell me the solution with writing the code?
Thanks in advance..
Can anyone solve that test coverage problem?
I posted my test class and uncovered code of controller.
How to cover the code can anyone write the code or atlest tell me how to cover the code for that?
Thank you in advance.