• Ruta Galanska
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hallo,
I wonder is it possible to cover Next() && Previous() Exception- Apex Messages in VF StandartSetController Test Class?
I dont think that rest of code is necessary for getting the idea, but if it's let me know.
The Idea of exceptions in Next/Previous is that it don't allow switch between VF pages before records (inline edit) is saved or canceled.

Do I have to create sepreate test method for pagination, do it right in existing method? Is there any way how i can create the exception situation? It's confusing as method tests are based on VFController SetController where is also SelectOption page size..and Next/Previous methods are defaults for class.

public Boolean hasNext{
        get{
            return setCon.getHasNext();
        }   
        set;
    }
   
    public void next() {  
        try{
        setCon.next();
        	} catch (Exception e) {
           		 ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.ERROR, 'Please Save or Cancel your changes in records. ERROR: ' + e.getMessage());

            	ApexPages.addMessage(myMsg);          
        	}
        }

    public Boolean hasPrevious  {
        get  {
            return setCon.getHasPrevious();
        } 
        set;
    }     
     
    public void previous() {   
        try{
        setCon.previous();
        } catch (Exception e){
           ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.ERROR, 'Please Save or Cancel your changes in records' + e.getMessage());

            ApexPages.addMessage(myMsg);    
        }
    }

Here is the Test Method. It covers everything except Next()&&Previous() Exception Apex Messages.
@isTest 
    
    @testSetup static void TestData(){  
        
        Account acct = new Account(name ='Test');
        insert acct;
        
        List <Contact> cnList = new List <Contact>();
        for (Integer i = 0; i<5; i++){
            cnList.add( new Contact(AccountId=acct.id, LastName= 'Test cnt'+ i));
        }
        insert cnList;   
    }

public static void testVfPage(){
        Account acc = [Select ID, Name From Account Where Name='Test'];
        
        List<Contact> query=[SELECT Id, AccountId, LastName
                             FROM Contact 
                             WHERE AccountId = :acc.id
                             LIMIT 6];
        System.assertEquals(5, query.size());
        //There is 5 contacts inserted, put limit 6 for purpose
        
        Test.startTest();
        PageReference pr = Page.VfPage;
        Test.setCurrentPage(pr);
        ApexPages.currentPage().getParameters().put('id', String.valueOf(acc.Id));
        
        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(query);
        stdSetController.setSelected(query);
        
       VfPageController t = new VfPageController();
        t.getContacts();
        
        //Buttons
        t.CustomCancel();
        t.CustomSave();          
        
        //Pages
        t.getTotalPages();       
        t.previous();
        t.next();
        t.refreshPageSize();
        
        Boolean test1 = t.hasNext;
        Boolean test2 = t.hasPrevious;
        Integer test3 = t.pageNumber;  
       Test.stopTest();
    }



 
I have been dealing with this issue for 2 days. When I click on Account Tab and select one of the account from list view, it gives me this error. I called technical support but they don't provide standard support to developer account. Please help me to solve this problem.

An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com! 

Error ID: 84564146-14190 (747219706)