2

I am writing one test class in which i have test the Selected Orders..

Here is my Main Class Code Portion which is not getting covered..

==Main Class code Portion======

    for(Orderc cOrd: orderlist) {
    if(cOrd.selected == true) {
        Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
        req.setComments(Comments);
        req.setAction('Approve');
        Id workItemId = getWorkItemId(cord.ord.id); 
        // submit the approval request for processing
        if(workItemId == null){
            cord.ord.addError('Error Occured');
        }
    }
}

Now here I am Not able to access the Selected Varibale which is in Wrapper Class As a Boolean Variable..

=====Wrapper Class code====

@TestVisible public class Orderc{
    public Boolean selected {get; set;}
}

=====Test class code that i am tryinhg====

public class Br_MassOrderApprovalTest {
    public static testMethod void VerifyOrders() {
        Br_OrderwrapperClassController foo  = new Br_OrderwrapperClassController();
        Br_OrderwrapperClassController.Orderc  obj = new Br_OrderwrapperClassController.Orderc();   
        //problem area: 
        obj .selected='true';
    }
}

error: Variable does not exist: Br_OrderwrapperClassController.Orderc.selected

Can anyone plaese suggest,thanks..

1
  • First, why you set a string value ('true') to your Boolean property?
    – highfive
    Sep 7 '15 at 5:55
2

Your selected variable is a atributte, you need instance your order and after that you init soul variable.

Example Test Code EDITED

    public static testMethod void VerifyOrders() {

    Br_OrderwrapperClassController controller  = new Br_OrderwrapperClassController();
    controller.orderList = new List<Br_OrderwrapperClassController.Orderc>();

    Br_OrderwrapperClassController.Orderc newOrderc = new Br_OrderwrapperClassController.Orderc();
    newOrderc.selected = true;

    controller.orderList.add(newOrderc);
}
5
  • Hi Torsen, thanks for your prompt reply...In my main class i have property set as public List<Br_OrderwrapperClassController.Orderc> Orderc{get; set;} so its giving me error as : Illegal assignment from Br_OrderwrapperClassController.Orderc to List&lt;Br_OrderwrapperClassController.Orderc&gt; uopn using your code, any idea.. Sep 7 '15 at 6:40
  • i edit my response. give me a second
    – Torsen
    Sep 7 '15 at 6:44
  • Can you add more code of your clases??
    – Torsen
    Sep 7 '15 at 6:50
  • Hi Torsen i have Edited my code, let me know if you have any Questions or confusion in the Requirement.. Sep 7 '15 at 7:59
  • Hi Prateek Jain, i edited my response. I init the order list and I add a order with selected = true.
    – Torsen
    Sep 7 '15 at 8:14
1

You're getting your variable because you're calling a method that is defined at the instance level at the class level. The setter for "selected" needs to be called on an INSTANCE of your inner class Orderc.

Where in your controller do you use the Orderc class? Probably, the code you need to write is something like

public class Br_MassOrderApprovalTest {
  public static testMethod void VerifyOrders() {
    Br_OrderwrapperClassController foo  = new Br_OrderwrapperClassController();
    foo.orderc.selected='true';
  }
}

Assuming that your controller foo has an orderc property that returns an instance of Br_OrderwrapperClassController.Orderc.

1
  • Hi Christian , thanks for writing back , even after calling it like foo.orderc.selected='true' and setting Property in foo..it given : Initial term of field expression must be a concrete SObject: List&lt;Br_OrderwrapperClassController.Orderc&gt; error, please help.. Sep 7 '15 at 6:28
1

The apex properties available inside of an inner class will be accessible by a property in the outer class.

public class Br_MassOrderApprovalTest {
    public static testMethod void VerifyOrders() {
        Br_OrderwrapperClassController foo = new Br_OrderwrapperClassController();
        foo.c0rd.selected=true;
    }
}

The property in outer class named c0rd should be used to access the property in the inner class.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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