1

The Below is the code for getting Multiselect picklist. Currently its returning null when i Run test class.

Class

 public List<string> Category{
    get; set;
    }

    public List < SelectOption > listcategory{
        get; set;
    }
           Schema.DescribeFieldResult fieldResult = Master__c.Type__c.getDescribe();    
            List<Schema.picklistEntry> ple = fieldResult.getPicklistValues(); 

             for(Schema.picklistEntry f:ple)    
            {    
                listcategory.add(new selectOption(f.getLabel(),f.getValue()));                                           
            } 

Where as the the Master__c.Type__c contains the values like

Actives,Passives,Misc and others

My Complete Controller runs on this snippet if its covered then my class will cover 100%.

So some one can let me know how to Pass the Above values into the Category field.

Test Class

@isTest
public class Testgenerate5 {

    static testMethod void testgenerate() {
             CreateDataHelper h = new CreateDataHelper();

             Product2 pr = h.CreateSingleproduct();
             insert pr;
             ProcurementAppSetup__c pba = h.createbilling();
             insert pba;



             Oper15 gbom = new Oper15 ();

             ApexPages.StandardController sc = new ApexPages.StandardController(boo);
             Oper15 ac = new Oper15 (sc);


             account a = h.CreateSingleAccount();
             insert a;

             Product2 p = h.CreateSingleproduct();
             insert p;

             Contact c = h.CreateSingleContact(a.id);
             insert c;

             MasterItem__c Mi = h.createMi();
             insert Mi;


             string indexParam = ApexPages.currentPage().getParameters().put('rowIndex', '0');

             Bom__c bb = h.createBom(p.id, pb.id);
             insert bb;

             Boolean disppop = false;

             gbom.setmallSelected();

     }
}
8
  • Make sure your picklist values are enabled on corresponding Record Types and/or Sales Processes.
    – Jac Uy
    Commented Jun 1, 2017 at 8:49
  • I dont see any requirement to set values in category field explicitly. It should be covered automatically. Would be great if you can share your entire class code and test class code. Commented Jun 1, 2017 at 8:50
  • Put a debug a check ple has any values.
    – Reshma
    Commented Jun 1, 2017 at 8:58
  • Nithish, at run time this snippet runs and covers this part but doesnt return any value when I debug the category it returns null. The code is very big I cannot past here the whole thing :( my bad
    – kishore
    Commented Jun 1, 2017 at 10:44
  • Reshma, ple has the orginal Picklist values from the msater object.
    – kishore
    Commented Jun 1, 2017 at 10:47

1 Answer 1

1

You could add this line in test class to assign value to Category before calling the method which executes the query.

gbom.Category = new List<String>{'Actives','Passives','Misc','others'};
2
  • Life Saver Reshma :) Thanks a TON, Covered 90% from 10% what was before :)
    – kishore
    Commented Jun 2, 2017 at 6:26
  • I tried the Same but I was using List<String>{'Actives';'Passives';'Misc';'others'};
    – kishore
    Commented Jun 2, 2017 at 6:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .