• A Raj 9
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 9
    Replies
Hi All, Plz help me out. This is the test class code for a button to delete all the sub object records. while saving it is giving error as "Constructor not defined: [PhaseDeleteAllLinesExt].<Constructor>(ApexPages.StandardController)"

below is the test class
******

@isTest
public class PhaseDeleteAllLinesExtTest {
        
        static testMethod void MyTest()
        {       

            list<opportunity> opp = [select id, name from opportunity where id='0060h000010bfWz'];
            
            Project_Phase_Plan__c  plan = new Project_Phase_Plan__c ();
            plan.Phase_Plan_Description__c = 'Testing';

            insert plan;
            
            Project_Phase__c phase = new Project_Phase__c();
            phase.Project_Phase__c = 1;
            phase.Trade__c = 'Glazier';

            insert phase ;
                        
            PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
            // VF Page name is 'ProjectPhaseDeleteAllLines'.
            pageRef.getparameters().put('Id', plan.id);
            Test.setCurrentPage(pageRef);

            Apexpages.StandardController sc = new Apexpages.StandardController(plan);
            PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);
            ext.deleteAllLines();     

           ext.close();

        }
    
         static testMethod void MyTest2()
             {
                Project_Phase__c phase = new Project_Phase__c();
                phase.Project_Phase__c=1;

            insert phase ;

            Project_Phase_Plan__c  plan = new Project_Phase_Plan__c ();
            plan.Phase_Plan_Description__c = 'Testing';

            insert plan;
             
            PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
            // VF Page name is 'ProjectPhaseDeleteAllLines'.
            Test.setCurrentPage(pageRef);

            Apexpages.StandardController sc = new Apexpages.StandardController(plan);
            PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);        
            ext.deleteAllLines();     

           ext.close();

        }
    }


 
Hi All, plz help me with test class code for this below apex class for a delete button to delete all the records of a sub object(Project_Phase) to a parent object(Project_Phase_Plan)

below is the code
********************

public class PhaseDeleteAllLinesExt
{
    public Project_Phase_Plan__c pplan{get;set;}
    public String deleteWarning{get;set;}
    public Boolean deleteOK{get;set;}
    public Boolean showCancel{get;set;}
    public Boolean showClose{get;set;}
    public Set<String> deleteAllOK  = new Set<String> {'Draft', 'Pre-Release Review', 'Confirmation Pending', 'Confirmed'};
    public PageReference currentPage = ApexPages.currentPage();
    
    public PhaseDeleteAllLinesExt(ApexPages.StandardSetController stdSetController)
    {
        //
        // Get the Order Release Information
        //
        deleteOK = false;
        showCancel = true;
        showClose = false;
        Id id = ApexPages.CurrentPage().getParameters().get('id');
        if (id != null)
        {
            System.debug('OER ID = ' + String.valueOf(id));
            pplan = [SELECT Id, Name FROM Project_Phase_Plan__c WHERE Id = :id LIMIT 1];
        }
        if (pplan == null)
        {
            ApexPages.Message noOEError = new ApexPages.Message(ApexPages.Severity.ERROR,'** ERROR - Unable to retrieve the Project Phase Plan Information');
            ApexPages.addMessage(noOEError);
            showClose = true;
            showCancel = false;         
        }
        else
        {
            
                deleteWarning = 'WARNING: You have requested the deletion of all Project Phase for Project Phase Plan ' + pplan.Name  + '<br>'+
                'Click the Continue button to confirm deletion; click the Cancel button to return to the OProject Phase Plan Without deleting the Lines';
                deleteOK = true;
          
        }
    
    }
    
    public PageReference close()
    {
       return new PageReference('javascript:window.self.close()');
    }
    
    public PageReference deleteAllLines()
    {
        List<Database.DeleteResult> drList = new List<Database.DeleteResult>();
        Boolean hasErrors = false;
        List<Project_Phase__c> linesToDelete = [SELECT Id, Project_Phase_Plan__c FROM Project_Phase__c WHERE Project_Phase_Plan__c = :pplan.Id];
        
        if (linesToDelete.size() > 0)
        {
            ApexPages.Message databaseErrorMsg;
            drList = Database.delete(linesToDelete, true);
            Integer i = 0;      

            for(Database.DeleteResult dr : drList)
            {
                if (!dr.isSuccess())
                {
                    hasErrors = true;
                    for(Database.Error err : dr.getErrors())
                    {
                        databaseErrorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, '*** An error occurred deleting Project Phase ID ' +
                            String.valueOf(linesToDelete[i].id) + '; ' + err.getMessage());
                        ApexPages.addMessage(databaseErrorMsg);
                    }
                }
                i++;
            }
        }
        if (hasErrors)
        {
            deleteWarning = 'Errors occurred while trying to delete the Project Phases; click the Cancel button to return to the Order Entry Release Page';
        }
        else
        {
            deleteWarning = String.valueOf(linesToDelete.size()) + ' Project Phase were successfully deleted.<br>' +
                'Close this window and then refresh the Project Phase Plan page to see the results';
        }
        deleteOK = false;
        showClose = true;
        showCancel = false;
        
        

        return currentPage;
 
        
    }
}

************************
 
Hi All, Below is the test class for a clone button. getting error on runing class as "List index Out of Bounds: 0 at both the line "obj01.CloneOER();"

Below is the test class code
=============================

@isTest
public class CloneOrderWithLines_Test {

    @testSetup
    static void setupTestData(){
        
        test.startTest();

        account account_Obj = new account(name='Testing Acc', Oracle_Customer_Number__c='Test Oracle');
        Insert account_Obj;
        system.debug('=============value of account_Obj================'+account_Obj);        

        opportunity opportunity_Obj = new opportunity(Name='Testing Opp', StageName='Closed - Does Not Qualify',
                                      Support_Region__c='New York', Target_SE__c='0054C000000XzsW', CloseDate=date.today(),
                                      Project_State__c='NY', Construction_Type__c='New Construction',
                                      Project_Name__c='Testing Proj', Project_Country__c='United States',
                                      Project_Building_Size__c='10K - 20K', Approx_glass_quantity__c=5,
                                      Project_Stage__c='Land Acquisition,Bid Awarded', Market_Segment__c='Education',
                                      Project_Glass_Installation_Timing__c='3 - 6 Months', LeadSource='Database');
        Insert opportunity_Obj;
        system.debug('=============value of account_Obj================'+opportunity_Obj);
        
        Order_Entry_Release__c Order_Entry_Release_Obj = new Order_Entry_Release__c(Release_Name__c = 'Testing Release',
                               Shipping_Account__c = account_Obj.id, Billing_Account__c = account_Obj.id,
                               Sold_to_Account__c= account_Obj.id, Opportunity__c=opportunity_Obj.id);

        system.debug('=============value of Shipping_Account__c================'+ Order_Entry_Release_Obj.Shipping_Account__c);
        system.debug('=============value of Billing_Account__c================'+ Order_Entry_Release_Obj.Billing_Account__c);

        Insert Order_Entry_Release_Obj;
        system.debug('=============value of Order_entry_release_Obj================'+ Order_Entry_Release_Obj);
        
        Order_Entry_Line__c Order_Entry_Line_Obj = new Order_Entry_Line__c(Order_Entry_Release__c = Order_Entry_Release_Obj.id,
                            Quantity__c = 1, Base_in__c = '15', Height_in__c = '20');
        Insert Order_Entry_Line_Obj;
        system.debug('=============value of Order_entry_line_Obj================'+ Order_Entry_Line_Obj);

        test.stopTest();
    }

    static testMethod void test_CloneOER_UseCase1(){
        
        List<Order_Entry_Release__c> Order_Entry_Release_Obj  =  [SELECT Id, Name, Release_Name__c, Shipping_Account__c,
                                     Billing_Account__c, Sold_to_Account__c from Order_Entry_Release__c];
        System.assertEquals(true, Order_Entry_Release_Obj.size()>0);
        
        List<Order_Entry_Line__c> Order_Entry_Line_Obj  =  [SELECT Id, Name, Order_Entry_Release__c, Quantity__c,
                                                            Base_in__c, Height_in__c from Order_Entry_Line__c];
        System.assertEquals(true, Order_Entry_Line_Obj.size()>0);

        CloneOrderWithLines obj01 = new CloneOrderWithLines(new ApexPages.StandardController(Order_Entry_Release_Obj[0]));
        
        system.debug('=============value of obj01================'+ obj01.newOER);

        obj01.oldOER = new Order_Entry_Release__c();
        obj01.newOER = new Order_Entry_Release__c();
        
        obj01.oerNumStr = '123';
        obj01.oerNum = 123;
        obj01.oerMap = new Map<Id, Order_Entry_Release__c>();
        obj01.maxOERNumber = 1;
        
        system.debug('=============value of obj01================'+ obj01);
        
        obj01.CloneOER();

    }
    

    static testMethod void test_CloneOER_UseCase2(){
    
        List<Order_Entry_Release__c> Order_Entry_Release_c_Obj  =  [SELECT Id, Name, Release_Name__c, Shipping_Account__c,
                                     Billing_Account__c, Sold_to_Account__c from Order_Entry_Release__c];
        System.assertEquals(true, Order_Entry_Release_c_Obj.size()>0);
    
        List<Order_Entry_Line__c> Order_Entry_Line_c_Obj  =  [SELECT Id, Name, Order_Entry_Release__c, Quantity__c,
                                                             Base_in__c, Height_in__c from Order_Entry_Line__c];
        System.assertEquals(true, Order_Entry_Line_c_Obj.size()>0);

        CloneOrderWithLines obj01 = new CloneOrderWithLines(new ApexPages.StandardController(Order_Entry_Release_c_Obj[0]));
    
        obj01.oldOER = new Order_Entry_Release__c();
        obj01.newOER = new Order_Entry_Release__c();

        obj01.oerNumStr = '123';
        obj01.oerNum = 123;
        obj01.oerMap = new Map<Id, Order_Entry_Release__c>();
        obj01.maxOERNumber = 1;

        Order_Entry_Release_c_Obj[0].Name='ReTesting';
        system.debug('=============value of Order_Entry_Release_c_Obj[0]================'+ Order_Entry_Release_c_Obj[0]);
        Update Order_Entry_Release_c_Obj[0];

        Order_Entry_Line_c_Obj[0].Base_in__c ='16';
        Order_Entry_Line_c_Obj[0].Height_in__c ='21';
        Order_Entry_Line_c_Obj[0].Quantity__c=1;

        Update Order_Entry_Line_c_Obj[0];
        system.debug('=============value of Order_Entry_Line_c_Obj[0]================'+ Order_Entry_Line_c_Obj[0]);
   
        obj01.CloneOER();
  }

}

=============================

 
Hi All, I wrote this Batch code, and is not showing any error and also it is running anonymously, but record is not getting updated

public class fieldupdate1 implements Database.Batchable<SObject>{
    public Database.querylocator start(Database.BatchableContext bc){
        string query = 'select id, name, industry from account';
        return database.getquerylocator(query);
        }

    public void execute(Database.BatchableContext bc, list<Account> scope){
        list<Account> accs = new list<account>();

        for(Account a : scope){
            
            for(integer i=25;i<30;i++){
                if(a.name == 'Test Batch'+i){a.industry='Agriculture';}
            accs.add(a);
            }
            
            }
        update accs;
        }
    
    public void finish(Database.BatchableContext bc){}
    
    }
Hi All, Plz help me out. This is the test class code for a button to delete all the sub object records. while saving it is giving error as "Constructor not defined: [PhaseDeleteAllLinesExt].<Constructor>(ApexPages.StandardController)"

below is the test class
******

@isTest
public class PhaseDeleteAllLinesExtTest {
        
        static testMethod void MyTest()
        {       

            list<opportunity> opp = [select id, name from opportunity where id='0060h000010bfWz'];
            
            Project_Phase_Plan__c  plan = new Project_Phase_Plan__c ();
            plan.Phase_Plan_Description__c = 'Testing';

            insert plan;
            
            Project_Phase__c phase = new Project_Phase__c();
            phase.Project_Phase__c = 1;
            phase.Trade__c = 'Glazier';

            insert phase ;
                        
            PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
            // VF Page name is 'ProjectPhaseDeleteAllLines'.
            pageRef.getparameters().put('Id', plan.id);
            Test.setCurrentPage(pageRef);

            Apexpages.StandardController sc = new Apexpages.StandardController(plan);
            PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);
            ext.deleteAllLines();     

           ext.close();

        }
    
         static testMethod void MyTest2()
             {
                Project_Phase__c phase = new Project_Phase__c();
                phase.Project_Phase__c=1;

            insert phase ;

            Project_Phase_Plan__c  plan = new Project_Phase_Plan__c ();
            plan.Phase_Plan_Description__c = 'Testing';

            insert plan;
             
            PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
            // VF Page name is 'ProjectPhaseDeleteAllLines'.
            Test.setCurrentPage(pageRef);

            Apexpages.StandardController sc = new Apexpages.StandardController(plan);
            PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);        
            ext.deleteAllLines();     

           ext.close();

        }
    }


 
Hi All, plz help me with test class code for this below apex class for a delete button to delete all the records of a sub object(Project_Phase) to a parent object(Project_Phase_Plan)

below is the code
********************

public class PhaseDeleteAllLinesExt
{
    public Project_Phase_Plan__c pplan{get;set;}
    public String deleteWarning{get;set;}
    public Boolean deleteOK{get;set;}
    public Boolean showCancel{get;set;}
    public Boolean showClose{get;set;}
    public Set<String> deleteAllOK  = new Set<String> {'Draft', 'Pre-Release Review', 'Confirmation Pending', 'Confirmed'};
    public PageReference currentPage = ApexPages.currentPage();
    
    public PhaseDeleteAllLinesExt(ApexPages.StandardSetController stdSetController)
    {
        //
        // Get the Order Release Information
        //
        deleteOK = false;
        showCancel = true;
        showClose = false;
        Id id = ApexPages.CurrentPage().getParameters().get('id');
        if (id != null)
        {
            System.debug('OER ID = ' + String.valueOf(id));
            pplan = [SELECT Id, Name FROM Project_Phase_Plan__c WHERE Id = :id LIMIT 1];
        }
        if (pplan == null)
        {
            ApexPages.Message noOEError = new ApexPages.Message(ApexPages.Severity.ERROR,'** ERROR - Unable to retrieve the Project Phase Plan Information');
            ApexPages.addMessage(noOEError);
            showClose = true;
            showCancel = false;         
        }
        else
        {
            
                deleteWarning = 'WARNING: You have requested the deletion of all Project Phase for Project Phase Plan ' + pplan.Name  + '<br>'+
                'Click the Continue button to confirm deletion; click the Cancel button to return to the OProject Phase Plan Without deleting the Lines';
                deleteOK = true;
          
        }
    
    }
    
    public PageReference close()
    {
       return new PageReference('javascript:window.self.close()');
    }
    
    public PageReference deleteAllLines()
    {
        List<Database.DeleteResult> drList = new List<Database.DeleteResult>();
        Boolean hasErrors = false;
        List<Project_Phase__c> linesToDelete = [SELECT Id, Project_Phase_Plan__c FROM Project_Phase__c WHERE Project_Phase_Plan__c = :pplan.Id];
        
        if (linesToDelete.size() > 0)
        {
            ApexPages.Message databaseErrorMsg;
            drList = Database.delete(linesToDelete, true);
            Integer i = 0;      

            for(Database.DeleteResult dr : drList)
            {
                if (!dr.isSuccess())
                {
                    hasErrors = true;
                    for(Database.Error err : dr.getErrors())
                    {
                        databaseErrorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, '*** An error occurred deleting Project Phase ID ' +
                            String.valueOf(linesToDelete[i].id) + '; ' + err.getMessage());
                        ApexPages.addMessage(databaseErrorMsg);
                    }
                }
                i++;
            }
        }
        if (hasErrors)
        {
            deleteWarning = 'Errors occurred while trying to delete the Project Phases; click the Cancel button to return to the Order Entry Release Page';
        }
        else
        {
            deleteWarning = String.valueOf(linesToDelete.size()) + ' Project Phase were successfully deleted.<br>' +
                'Close this window and then refresh the Project Phase Plan page to see the results';
        }
        deleteOK = false;
        showClose = true;
        showCancel = false;
        
        

        return currentPage;
 
        
    }
}

************************
 
Hi All, Below is the test class for a clone button. getting error on runing class as "List index Out of Bounds: 0 at both the line "obj01.CloneOER();"

Below is the test class code
=============================

@isTest
public class CloneOrderWithLines_Test {

    @testSetup
    static void setupTestData(){
        
        test.startTest();

        account account_Obj = new account(name='Testing Acc', Oracle_Customer_Number__c='Test Oracle');
        Insert account_Obj;
        system.debug('=============value of account_Obj================'+account_Obj);        

        opportunity opportunity_Obj = new opportunity(Name='Testing Opp', StageName='Closed - Does Not Qualify',
                                      Support_Region__c='New York', Target_SE__c='0054C000000XzsW', CloseDate=date.today(),
                                      Project_State__c='NY', Construction_Type__c='New Construction',
                                      Project_Name__c='Testing Proj', Project_Country__c='United States',
                                      Project_Building_Size__c='10K - 20K', Approx_glass_quantity__c=5,
                                      Project_Stage__c='Land Acquisition,Bid Awarded', Market_Segment__c='Education',
                                      Project_Glass_Installation_Timing__c='3 - 6 Months', LeadSource='Database');
        Insert opportunity_Obj;
        system.debug('=============value of account_Obj================'+opportunity_Obj);
        
        Order_Entry_Release__c Order_Entry_Release_Obj = new Order_Entry_Release__c(Release_Name__c = 'Testing Release',
                               Shipping_Account__c = account_Obj.id, Billing_Account__c = account_Obj.id,
                               Sold_to_Account__c= account_Obj.id, Opportunity__c=opportunity_Obj.id);

        system.debug('=============value of Shipping_Account__c================'+ Order_Entry_Release_Obj.Shipping_Account__c);
        system.debug('=============value of Billing_Account__c================'+ Order_Entry_Release_Obj.Billing_Account__c);

        Insert Order_Entry_Release_Obj;
        system.debug('=============value of Order_entry_release_Obj================'+ Order_Entry_Release_Obj);
        
        Order_Entry_Line__c Order_Entry_Line_Obj = new Order_Entry_Line__c(Order_Entry_Release__c = Order_Entry_Release_Obj.id,
                            Quantity__c = 1, Base_in__c = '15', Height_in__c = '20');
        Insert Order_Entry_Line_Obj;
        system.debug('=============value of Order_entry_line_Obj================'+ Order_Entry_Line_Obj);

        test.stopTest();
    }

    static testMethod void test_CloneOER_UseCase1(){
        
        List<Order_Entry_Release__c> Order_Entry_Release_Obj  =  [SELECT Id, Name, Release_Name__c, Shipping_Account__c,
                                     Billing_Account__c, Sold_to_Account__c from Order_Entry_Release__c];
        System.assertEquals(true, Order_Entry_Release_Obj.size()>0);
        
        List<Order_Entry_Line__c> Order_Entry_Line_Obj  =  [SELECT Id, Name, Order_Entry_Release__c, Quantity__c,
                                                            Base_in__c, Height_in__c from Order_Entry_Line__c];
        System.assertEquals(true, Order_Entry_Line_Obj.size()>0);

        CloneOrderWithLines obj01 = new CloneOrderWithLines(new ApexPages.StandardController(Order_Entry_Release_Obj[0]));
        
        system.debug('=============value of obj01================'+ obj01.newOER);

        obj01.oldOER = new Order_Entry_Release__c();
        obj01.newOER = new Order_Entry_Release__c();
        
        obj01.oerNumStr = '123';
        obj01.oerNum = 123;
        obj01.oerMap = new Map<Id, Order_Entry_Release__c>();
        obj01.maxOERNumber = 1;
        
        system.debug('=============value of obj01================'+ obj01);
        
        obj01.CloneOER();

    }
    

    static testMethod void test_CloneOER_UseCase2(){
    
        List<Order_Entry_Release__c> Order_Entry_Release_c_Obj  =  [SELECT Id, Name, Release_Name__c, Shipping_Account__c,
                                     Billing_Account__c, Sold_to_Account__c from Order_Entry_Release__c];
        System.assertEquals(true, Order_Entry_Release_c_Obj.size()>0);
    
        List<Order_Entry_Line__c> Order_Entry_Line_c_Obj  =  [SELECT Id, Name, Order_Entry_Release__c, Quantity__c,
                                                             Base_in__c, Height_in__c from Order_Entry_Line__c];
        System.assertEquals(true, Order_Entry_Line_c_Obj.size()>0);

        CloneOrderWithLines obj01 = new CloneOrderWithLines(new ApexPages.StandardController(Order_Entry_Release_c_Obj[0]));
    
        obj01.oldOER = new Order_Entry_Release__c();
        obj01.newOER = new Order_Entry_Release__c();

        obj01.oerNumStr = '123';
        obj01.oerNum = 123;
        obj01.oerMap = new Map<Id, Order_Entry_Release__c>();
        obj01.maxOERNumber = 1;

        Order_Entry_Release_c_Obj[0].Name='ReTesting';
        system.debug('=============value of Order_Entry_Release_c_Obj[0]================'+ Order_Entry_Release_c_Obj[0]);
        Update Order_Entry_Release_c_Obj[0];

        Order_Entry_Line_c_Obj[0].Base_in__c ='16';
        Order_Entry_Line_c_Obj[0].Height_in__c ='21';
        Order_Entry_Line_c_Obj[0].Quantity__c=1;

        Update Order_Entry_Line_c_Obj[0];
        system.debug('=============value of Order_Entry_Line_c_Obj[0]================'+ Order_Entry_Line_c_Obj[0]);
   
        obj01.CloneOER();
  }

}

=============================

 
Hi All, I wrote this Batch code, and is not showing any error and also it is running anonymously, but record is not getting updated

public class fieldupdate1 implements Database.Batchable<SObject>{
    public Database.querylocator start(Database.BatchableContext bc){
        string query = 'select id, name, industry from account';
        return database.getquerylocator(query);
        }

    public void execute(Database.BatchableContext bc, list<Account> scope){
        list<Account> accs = new list<account>();

        for(Account a : scope){
            
            for(integer i=25;i<30;i++){
                if(a.name == 'Test Batch'+i){a.industry='Agriculture';}
            accs.add(a);
            }
            
            }
        update accs;
        }
    
    public void finish(Database.BatchableContext bc){}
    
    }

I'm getting the followig error in my test method:

constructor not defined: [AccountOpenCasesExtension].<Constructor>()

 

I instantiated the class file and called my initialize method that is called within the constructor.  I'm not clear on why the constructor is not defined.  Shouldn't the constructor execute when the class is instantiated?

 

Here is my class file:

 

public class AccountOpenCasesExtension { private List<Account> accounts; public List<Account> getAccounts() { return accounts; } public AccountOpenCasesExtension(ApexPages.StandardController stdController) { init((Account)stdController.getRecord()); //accounts = [Select id, name, (Select Owner.Name, Contact.Name, CaseNumber, Subject, CreatedDate From Cases WHERE IsClosed = false) From Account a WHERE id =: stdController.getId()]; } public void init(Account a) { accounts = [Select id, name, (Select Owner.Name, Contact.Name, CaseNumber, Subject, CreatedDate From Cases WHERE IsClosed = false) From Account a WHERE id =: a.Id]; } static testMethod void test() { Account acct = [Select id, name, (Select Owner.Name, Contact.Name, CaseNumber, Subject, CreatedDate From Cases WHERE IsClosed = false) From Account a LIMIT 1]; AccountOpenCasesExtension ctrl = new AccountOpenCasesExtension(); ctrl.init(acct); } }