• ranjith1.3929645002009956E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi All,

I have a Requirement like this,
I want to search a List Of Records on Opportunity,
Initially iam able to sort the records when i click on Column Header,
but after filtering  the  records when i click on Column Header it will sort either ascending  or descending,
but it is  not happening.

How do we do that?

Thanks in  advance.............


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.


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 advance.
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.

I don't understand my compile error, any ideas? see error line below in red (

Error: Compile Error: expecting a semi-colon, found '(' at line 55 column 29)

 

public class ProductRenewalInformationPageController {

public account a {get;set;}
public Boolean editMode {get;set;}
public Boolean editAccess {get;set;}
public Boolean isAdmin {get;set;}

public productRenewalInformationPageController(ApexPages.standardController std){

editMode = false;
if(a == null) a = [
SELECT name, OwnerId, CreatedDate, Product_Domain_Protect__c, Product_EIS_Gold__c, Product_EIS_Platinum__c,
Product_Certification__c, Product_Additional_AM_Services__c,Product_Email_Client_Monitor__c, Product_Professional_Services__c,
Product_EIS_Internal_Use__c, Product_General_Referral__c,Product_EIS_Child__c, Product_Tools_Reseller_API__c, Product_Cert_Referral_Framework__c,
Product_Certification_Referral_Child__c, Product_Tools_Reseller_Framework__c,Product_Inbox_Insight__c, Product_Email_Brand_Monitor__c, Product_Email_Brand_Monitor_Child__c,
Product_Domain_Protect_Child__c, Product_Domain_Secure__c, Product_Domain_Secure_Child__c
FROM account WHERE id = :ApexPages.currentPage().getParameters().get('id')
];

//determine if user can make changes

user u =[select id, profile.name from user where id = :userinfo.getuserid()];

if(u.profile.name == 'Exec Admin' || u.profile.name == 'Finance'){
isAdmin = true;
} else {isAdmin = false;}

if(isAdmin == true){
editAccess = true;
} else {editAccess = false;}

{

// only proceed if the user has edit rights
if(editAccess = true) {

//editMode is used as a view state variable (only Admin and Finance can edit) Initializes as false but once true page rerenders to display inputfields rather than output fields
if(editMode == false) {
editMode = true;
} else {
// this part of the code is where any values that were entered by the use are saved
editMode = false;

update a;
return null;

}

} else {
if(editAccess == false) ApexPages.addMessage (new ApexPages.Message(ApexPages.Severity.ERROR,'You are not authorized to make changes to this page.'));
return null;
}
}

public PageReference save() {
update a;
return (new ApexPages.StandardController(account)).view();
}


}