function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt TindallMatt Tindall 

testSaveFailed

Im trying to deploy the following class:

public with sharing class SkipSearchController{

    // The SOQL without the order and limit
        private String soql {get;set;}
    
    // The collection of Skip Companys to get
        public List<Skip_Supplier__c> suppliers {get;set;}
    
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
                public String sortField {
                        get  { if (sortField == null) {sortField = 'Postcode_Prefix__c'; } return sortField;  }
                        set;
                }
    
        // format the soql for display on the visualforce page
                public String debugSoql {
                        get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
                        set;
                }
    
        // init the controller and display some sample data when the page loads
                public SkipSearchController() {
                        soql = 'select Postcode_Prefix__c, X2_Yard__c, X2_Yard_Enclosed__c, X2_Yard_Plasterboard__c, X3_Yard__c, X3_Yard_Enclosed__c, X3_Yard_Plasterboard__c, X4_Yard__c, X4_Yard_Enclosed__c, X4_Yard_Plasterboard__c, X5_Yard__c, X5_Yard_Enclosed__c, X5_Yard_Plasterboard__c, X6_Yard__c, X6_Yard_Enclosed__c, X6_Yard_Plasterboard__c, X8_Yard__c, X8_Yard_Enclosed__c, X8_Yard_Plasterboard__c, X10_Yard__c, X10_Yard_Enclosed__c, X10_Yard_Plasterboard__c, X12_Yard__c, X12_Yard_Enclosed__c, X12_Yard_Plasterboard__c, X14_Yard__c, X14_Yard_Enclosed__c, X14_Yard_Plasterboard__c, X16_Yard__c, X16_Yard_Enclosed__c, X16_Yard_Plasterboard__c, Supplier_Name__c  from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                runQuery();
                }
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                try {
                        suppliers = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
                } catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                }
        }
            
        // runs the search with parameters passed via Javascript
                public PageReference runSearch() {
                        String Postcode = Apexpages.currentPage().getParameters().get('Postcode');
                        String Supplier = Apexpages.currentPage().getParameters().get('Supplier');
            
           soql = 'select Postcode_Prefix__c, X2_Yard__c, X2_Yard_Enclosed__c, X2_Yard_Plasterboard__c, X3_Yard__c, X3_Yard_Enclosed__c, X3_Yard_Plasterboard__c, X4_Yard__c, X4_Yard_Enclosed__c, X4_Yard_Plasterboard__c, X5_Yard__c, X5_Yard_Enclosed__c, X5_Yard_Plasterboard__c, X6_Yard__c, X6_Yard_Enclosed__c, X6_Yard_Plasterboard__c, X8_Yard__c, X8_Yard_Enclosed__c, X8_Yard_Plasterboard__c, X10_Yard__c, X10_Yard_Enclosed__c, X10_Yard_Plasterboard__c, X12_Yard__c, X12_Yard_Enclosed__c, X12_Yard_Plasterboard__c, X14_Yard__c, X14_Yard_Enclosed__c, X14_Yard_Plasterboard__c, X16_Yard__c, X16_Yard_Enclosed__c, X16_Yard_Plasterboard__c, Supplier_Name__c  from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                        if (!Postcode.equals(''))
                                soql += ' and Postcode_Prefix__c LIKE \''+String.escapeSingleQuotes(Postcode)+'%\'';
                        if (!Supplier.equals(''))
                                soql += ' and Supplier_Name__c LIKE \''+String.escapeSingleQuotes(Supplier)+'%\'';
                
                        // run the query again
                        runQuery();
 
                        return null;
                }

    
}

 But i am getting the follwoing error:

API Name:AdvVFWebinarViewStateExtension.testSaveFailedBecauseOfOpportunityValidationRu...
Type: Class
Line 123
Column: 1
Problem: Failure Message: "System.AssertException: Assertion Failed: Should not have been redirected.", Failure Stack Trace: "Class.AdvVFWebinarViewStateExtension.testSaveFailedBecauseOfOpportunityValidationRule: line 123, column 1"

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan
Hi,

By reading your error message, i came to understand that your assumption value is wrong in your test class.

Check your test class line number 123 and check whether you are giving a correct values in System.Assert(.....)
Matt TindallMatt Tindall

I dont have that many lines in my test code? See below.

@isTest
public class SkipSearchControllertest{
    
    static testMethod void mySupplierTest(){
     
        PageReference pageRef = Page.SkipSupplierPage;
        
        Test.setCurrentPageReference(pageRef);
        
        pageRef.getParameters().put('Postcode','Test');
        pageRef.getParameters().put('Supplier','Test');
        SkipSearchController MyPageCon = new SkipSearchController();
        

        System.assert(MyPageCon.runSearch() == null);
        
    
    }
}

 

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

Fine, in your test class change the line System.assert(MyPageCon.runSearch() == null); as shown highlighted below and run the test class again,

 

@isTest
public class SkipSearchControllertest{   
    static testMethod void mySupplierTest(){    
        PageReference pageRef = Page.SkipSupplierPage;       
        Test.setCurrentPageReference(pageRef);  

             
         String postcode = Apexpages.currentpage().getParameters().put('Postcode','Test');  //to be stored in Skip_Supplier__c
         String supplier = Apexpages.currentpage().getParameters().put('Supplier','Test');


         SkipSearchController MyPageCon = new SkipSearchController();  

 

         // Include the below insert statement with the values you passed in parameters postcode

         Skip_Supplier__c ss = new  Skip_Supplier__c( Postcode_Prefix__c = postcode,

                                                                                                Supplier_Name__c = supplier,

                                                                                                <insert other field values requrired..>);   

         insert ss;  

          
        MyPageCon.runSearch();     // Add this line instead of system.assert
        }
}

 


Try the above testclass and check the result. And the insert statement is to check the following query in the controller,

 

public PageReference runSearch() {
                        String Postcode = Apexpages.currentPage().getParameters().get('Postcode');
                        String Supplier = Apexpages.currentPage().getParameters().get('Supplier');
            
           soql = 'select Postcode_Prefix__c, X2_Yard__c, X2_Yard_Enclosed__c, X2_Yard_Plasterboard__c, X3_Yard__c, X3_Yard_Enclosed__c, X3_Yard_Plasterboard__c, X4_Yard__c, X4_Yard_Enclosed__c, X4_Yard_Plasterboard__c, X5_Yard__c, X5_Yard_Enclosed__c, X5_Yard_Plasterboard__c, X6_Yard__c, X6_Yard_Enclosed__c, X6_Yard_Plasterboard__c, X8_Yard__c, X8_Yard_Enclosed__c, X8_Yard_Plasterboard__c, X10_Yard__c, X10_Yard_Enclosed__c, X10_Yard_Plasterboard__c, X12_Yard__c, X12_Yard_Enclosed__c, X12_Yard_Plasterboard__c, X14_Yard__c, X14_Yard_Enclosed__c, X14_Yard_Plasterboard__c, X16_Yard__c, X16_Yard_Enclosed__c, X16_Yard_Plasterboard__c, Supplier_Name__c  from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null';
                        if (!Postcode.equals(''))
                                soql += ' and Postcode_Prefix__c LIKE \''+String.escapeSingleQuotes(Postcode)+'%\'';
                        if (!Supplier.equals(''))
                                soql += ' and Supplier_Name__c LIKE \''+String.escapeSingleQuotes(Supplier)+'%\'';
                
                        // run the query again
                        runQuery();
 
                        return null;
                }

 

 

All the highlighted lines are for your identification.

 

Hope this will help you...!

 

Please don't forget to give kudos and mark this as a solution, if this works out.