• Deb Flores 1
  • NEWBIE
  • 10 Points
  • Member since 2014
  • Quad Learning

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi everyone!  I'm a fairly new Apex coder (I'm an old Assembler programmer from back in the day :-)  but still learning Java and Apex), and I can't figure out why this test class won't compile.  I have a feeling it's something very obvious that I'm overlooking, because 1) it's a very basic test class, and 2) I'm using virtually the same code in another test class and it works swimmingly.  If someone would be kind enough to take a look and point out the error, I'd really appreciate it!

Here's the test class:
@isTest(SeeAllData=true)
private class UtilGetPickListValuesTest {
   static testmethod void testPickListValues() {

	Test.startTest();
	list<SelectOption> plValues = new list<SelectOption>();	
	plValues = UtilGetPickListValues.getPicklistValues(Opportunity, 'StageName');
	System.debug('plValues = ' + plValues); 
	Test.stopTest();
	
	System.assert(plValues.size() > 0);
   }
}
and here's the utility class it will cover:
global without sharing class UtilGetPickListValues {
	
// Get a list of picklist values from an existing object field.
   global static list<SelectOption> getPicklistValues(SObject obj, String fld)
   {
      list<SelectOption> options = new list<SelectOption>();
      // Get the object type of the SObject.
      Schema.sObjectType objType = obj.getSObjectType(); 
      // Describe the SObject using its object type.
      Schema.DescribeSObjectResult objDescribe = objType.getDescribe();       
      // Get a map of fields for the SObject
      map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap(); 
      // Get the list of picklist values for this field.
      list<Schema.PicklistEntry> values =
         fieldMap.get(fld).getDescribe().getPickListValues();
      // Add these values to the selectoption list.
      for (Schema.PicklistEntry a : values)
      { 
         options.add(new SelectOption(a.getLabel(), a.getValue())); 
      }
      return options;
   }

}

And while I'm writing, I'd like to say thanks to all of you who take time to offer your help and advice on the developer community!  It is an invaluable resource to me, and I'm sure to many others as well!

Deb



 
Hi everyone!  I'm a fairly new Apex coder (I'm an old Assembler programmer from back in the day :-)  but still learning Java and Apex), and I can't figure out why this test class won't compile.  I have a feeling it's something very obvious that I'm overlooking, because 1) it's a very basic test class, and 2) I'm using virtually the same code in another test class and it works swimmingly.  If someone would be kind enough to take a look and point out the error, I'd really appreciate it!

Here's the test class:
@isTest(SeeAllData=true)
private class UtilGetPickListValuesTest {
   static testmethod void testPickListValues() {

	Test.startTest();
	list<SelectOption> plValues = new list<SelectOption>();	
	plValues = UtilGetPickListValues.getPicklistValues(Opportunity, 'StageName');
	System.debug('plValues = ' + plValues); 
	Test.stopTest();
	
	System.assert(plValues.size() > 0);
   }
}
and here's the utility class it will cover:
global without sharing class UtilGetPickListValues {
	
// Get a list of picklist values from an existing object field.
   global static list<SelectOption> getPicklistValues(SObject obj, String fld)
   {
      list<SelectOption> options = new list<SelectOption>();
      // Get the object type of the SObject.
      Schema.sObjectType objType = obj.getSObjectType(); 
      // Describe the SObject using its object type.
      Schema.DescribeSObjectResult objDescribe = objType.getDescribe();       
      // Get a map of fields for the SObject
      map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap(); 
      // Get the list of picklist values for this field.
      list<Schema.PicklistEntry> values =
         fieldMap.get(fld).getDescribe().getPickListValues();
      // Add these values to the selectoption list.
      for (Schema.PicklistEntry a : values)
      { 
         options.add(new SelectOption(a.getLabel(), a.getValue())); 
      }
      return options;
   }

}

And while I'm writing, I'd like to say thanks to all of you who take time to offer your help and advice on the developer community!  It is an invaluable resource to me, and I'm sure to many others as well!

Deb