-1

This question already has an answer here:

I havent written any test classes before and I am having trouble getting started. Can someone help me put something together for this?

I'm trying to insert a record with a certain field value (Clone__c = TRUE) then query for it (app), and then use system.assert to check that the size of the returned list of results (app) equals 1.

But this is the error I'm getting:

Error: Compile Error: Variable does not exist: app at line 53 column 27

Below is my test class:

    @isTest 
Public class test_MatterApprovals{
     public static testmethod void testMatterApprovals(){

         List<NST_Approval__c> NSTapprovals = new List<NST_Approval__c>();
         List<NST_Approval__c> clonedNSTapprovals = new List<NST_Approval__c>();
         List<Matter__c> matters = new List<Matter__c>();
         List<Approvals__c> app = new List<Approvals__c>();
         List<NST_Approval__c> nst = new List<NST_Approval__c>();
         List<Approvals__c> applist = new List<Approvals__c>();




         matters = [SELECT CNID__c, Agreement_Number__c, Id 
                     FROM Matter__c 
                     WHERE Status__c ='In Progress' 
                     AND OwnerId=:userinfo.getUserId() 
                     AND Matter_Type__c = 'Agreement' 
                     ORDER BY Agreement_Number__c ASC]; 

         insert matters;



          Approvals__c appRec = new Approvals__c();
              appRec.Regions_Expected_for_Client_Business__c = 'EMEA';
              appRec.Counterparty_Type__c = 'Asset Management';
              appRec.Desks_to_Approve__c = 'CCRM';
              appRec.Clone__c=TRUE;

          insert appRec;




         Matter__c testMatt = new Matter__c();
         testMatt.name='Test1';
         insert testMatt;

         PageReference pageRef = Page.appFlowPagev2;
         Test.setCurrentPage(pageRef);
         pageRef.getParameters().put('Id',String.valueof(testMatt.Id));
         ApexPages.StandardController sc = new ApexPages.StandardController(testMatt);
         MatterApprovals testMattApp = new MatterApprovals(sc);


         app=[Select ID, Name, CreatedById, Clone__C, Selected__c 
                                   FROM Approvals__c 
                                   WHERE (Clone__c = TRUE OR Selected__c = TRUE)
                                   AND CreatedById=:userinfo.getUserId()];        

         system.assert(sc.app.size()==1);

Below is my class: public class MatterApprovals { public ApexPages.StandardController std; public String message{get;set;} Datetime pastFiveBack = Datetime.now().addMinutes(-15); public List NSTapprovals {get; set;} public List clonedNSTapprovals {get; set;} public user currentuser{get; set;} public string cnidSort {get; set;}

    public MatterApprovals(ApexPages.StandardController stdCtrl)
    {
     std=stdCtrl;
     NSTapprovals=[select id, Name,Original_Clause_Language__c, Selected__c, Proposed_Clause_Language__c, Clause_Name__c, Clone__c, Ribbon_Clause_Name__c,Applicable_CSIDs__c, Business_Rationale__c, Negotiator_Comments__c, Matter__c, Master_Approval_Name__r.Desks_to_Approve__c,Master_Approval_Name__r.Regions_Expected_for_Client_Business__c, Master_Approval_Name__r.KAM_Client__c, Master_Approval_Name__r.Counterparty_Type__c,Master_Approval_Name__r.Client_Priority_Level__c,Master_Approval_Name__r.Additional_Details__c,Master_Approval_Name__r.Investment_Manager__c, Additional_NST_Details__c, Document_Clause__c,Master_Approval_Name__r.Transition_Manager__c, Master_Approval_Name__r.Strategy__c from NST_Approval__c where Matter__c=:std.getId() AND Submission_Action__c IN ('Creation') order by Name];


    clonedNSTapprovals=[select id, Name, Matter__c, Clause_Name__c, Master_Approval_Name__r.CNID__c, Additional_NST_Details__c, Master_Approval_Name__r.Name, Master_Approval_Name__r.Original_Approval_Id__c, Master_Approval_Name__r.Matter__c, Master_Approval_Name__r.Status__c from NST_Approval__c where CreatedDate>= :pastFiveBack AND Master_Approval_Name__r.OwnerId=:userinfo.getUserId() AND Master_Approval_Name__r.Original_Approval_Id__c != null ORDER BY Master_Approval_Name__r.Matter__c ASC];


        selectedMatters = new List<SelectOption>();
        List<Matter__c> matters = [SELECT CNID__c, Agreement_Number__c, Id FROM Matter__c WHERE Status__c ='In Progress' AND OwnerId=:userinfo.getUserId() AND Matter_Type__c = 'Agreement' ORDER BY Agreement_Number__c ASC];  



        allMatters= new List<SelectOption>();  

        for ( Matter__c m : matters ) {
            string cnidSort = m.Agreement_Number__c + '___' + m.CNID__c;
            allMatters.add(new SelectOption(m.Id, cnidSort));
        }
//        SelectOptionSorter.doSort(allMatters, SelectOptionSorter.FieldToSort.Label);


    }

//////////New Stuff//////////////////    

   public Flow.Interview.Approvals_MultiViewClone_Auto_finalversion myFlow {get; set;}
   public string value {get; set;}
   public string vfMyCNIDs {get; set;}
   public List<Approvals__c> createdApprovals {get; set;}

    public PageReference save()
    {
     // first save the matter
     std.save();

     try{      
         // then save the approvals
         update NSTapprovals;

        PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
        pageRef.setRedirect(True);
        return null;
        }

     catch(Exception ex)
        {
         ApexPages.addMessages(ex);
         }     

        PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
        pageRef.setRedirect(True);
        return null;
     }

    public PageReference start() {


    update NSTapprovals;   

    messageupdate ='';
    Boolean first = true;
    for ( SelectOption so : selectedMatters ) {
        if (!first) {
            messageupdate += ', ';
        }
//        messageupdate += so.getLabel() + ' (' + so.getValue() + ')';
        messageupdate += so.getValue();
        first = false;
    }

    Map<String, Object> myCNIDMap = new Map<String, Object>();


    IF(messageupdate != null){ 
            myCNIDMap.put('vmyCNIDs',messageupdate);
            Flow.Interview.Approvals_MultiViewClone_Auto_finalversion myflow = new Flow.Interview.Approvals_MultiViewClone_Auto_finalversion(myCNIDMap);
            myFlow.start();



      List<Approvals__c> createdApprovals =
          (List<Approvals__c>) myflow.getVariableValue('socv_NewApprovalHeaders');

       try {
            for(Approvals__c approval: createdApprovals)
            System.debug('My check'+ approval.Matter__c+ ' mmmmyyyycheck' );
           }
       catch (System.NullPointerException e) {
           System.debug('The following exception has occurred: ' + e.getMessage());
           }



        } else { 
           System.debug('The following exception has occurred');
        }

        string matterId = ApexPages.currentPage().getParameters().get('Id');

     //*Clear Clones and Submissions from Approvals*//               
        List<Approvals__c> app=[Select ID, Name, CreatedById, Clone__C, Selected__c 
                                   FROM Approvals__c 
                                   WHERE (Clone__c = TRUE OR Selected__c = TRUE)
                                   AND CreatedById=:userinfo.getUserId()        ];

            For(Approvals__c oneapp: app){
                    oneapp.Clone__c = False;
                    oneapp.Selected__c = False;                
                }
            update app;


        //*Clear Clones and Submissions from NST Approvals*//               
        List<NST_Approval__c> nst=[Select ID, Name, CreatedById, Clone__C, Selected__c 
                                   FROM NST_Approval__c 
                                   WHERE (Clone__c = TRUE OR Selected__c = TRUE)
                                   AND CreatedById=:userinfo.getUserId()        ];

            For(NST_Approval__c onenst: nst){
                    onenst.Clone__c = False;
                    onenst.Selected__c = False;                
                }
            update nst;                  

        PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
        pageRef.setRedirect(True);
        return null;




     }

///////////////////////////////////picklist//////////////////////////////////
    public SelectOption[] selectedMatters { get; set; }
    public SelectOption[] allMatters { get; set; }
    public String messageupdate { get; set; }


/////////////////////greyed out field///////////////////////////////////////
//    public string addNstDetail { get; set; }
//    public Boolean bool { get; set; }
//
//    string addNstDetail
//    public void selectable() {
//        if(ISBLANK(NSTApproval.Additional_NST_Details__c)) { 
//            bool = TRUE;
//             }
//        else {
//             bool = FALSE;
//             }
//    }

}

marked as duplicate by Eric apex Oct 20 '17 at 20:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Try adding some lines that will initialize your list variables

Something like the below example:

NSTapprovals = new List<sObject>();
clonedNSTapprovals = new List<sObject>();

Not the answer you're looking for? Browse other questions tagged or ask your own question.