Saturday 29 September 2012

Getting Picklist Fields From Object and Their Values In Apex


Today i need to finding picklist type fields and their values in my project it's very easy and simple so i want to share my code with you guys. I know some of us know about this but useful for new buddy's 

 // This Map hold all the fields of Opportunity 
 //   { If you want fields of other object replace Opportunity by other object api name}

 Map<String, Schema.SObjectField> M = Schema.SObjectType.Opportunity.fields.getMap();

 //This Map of list hold the picklist fields and picklist values 
 Map<String ,List<Schema.PicklistEntry>> MapofPicklistfieldswithValues 
                                                       = new Map<String ,List<Schema.PicklistEntry>>();

//Now we are itreating field and find that field which is picklist type and keep in our map 
 with their picklist values
  for(Schema.SObjectField x :M.values())
  {
       if(String.valueOf(M.get(String.valueOf(x)).getDescribe().getType())=='PICKLIST')
        {
          //now we find it the field which is picklist type and now we are puting its name and value in Map
           MapofPicklistfieldswithValues.put(String.valueOf(x ),
                                                                   M.get(String.valueOf(x)).getDescribe().getPicklistValues());
         }
  }

  System.debug('Api name of field which are picklist type ::: -'+MapofPicklistfieldswithValues.keyset());

  for(String fieldApiName : MapofPicklistfieldswithValues.keySet())
  {
       for(Schema.PicklistEntry Picklistvalue :MapofPicklistfieldswithValues.get(fieldApiName) )
      {
             System.debug('Name of field:::'+fieldApiName + '_______Picklist values :::'                                         
                                                                                 +Picklistvalue.getValue());
       }
 }

Thanks,

Regards,
Ashlekh Gera.

Wednesday 12 September 2012

Cloud Trivia Winter#13

Hi friends,

This is the all questions which was asked on cloud trivia. This all question are belongs to winter 13 release.
If you want to play cloud trivia and want win prizes then flow @forcedotcom on twitter and  
 to find me @AshlekhGera


 Que 1  What Object type now has dozens of new methods? 
 Ans    String

Que 2   What does the “exec” command do in the Command Line Window of the developer console? 
Ans      Query & Generate log

Que 3  True/False: You can run tests using the Tests tool for any combination of classes you select
            (one, many, all, etc)? 
Ans     True

Que 4  As of #Winter13, there are now HTTP callouts for which two APIs? 
Ans     Callout testing of SOAP and REST services

Que 5 Where can you now load test data from as of #Winter13? 
Ans    load from static resources(CSVs) to test cases

Que 6 Name 2 of the other new tools (besides Perspectives) added to the developer console in #Winter13? 
Ans   #cloudtrivia - Query Editor & Command Line

Que 7 What does “Perspectives” allow you to do in the developer console? 
Ans   When you open a debug log in the Developer Console, it opens in a System Log view which is a collection of panels for analyzing the log. In the Winter ‘13 release, you can create perspectives in a System Log view.

Que 8  What set of tools will be piloted in #Winter13 to allow you to integrate external applications in Salesforce? 
 Ans    Canvas

Que 9: What two formula functions were added for working with the beta Geolocation Custom Field type? 
Ans     DISTANCE and GEOLOCATION

Que 10 Name 5 of the 7 chart types for Visualforce Charting? 
Ans       area, gauge, radar, scatter, bar

Que 11 What prefix should you use to “pass through” attributes in the <apex:outputPanel> component? 
Ans     HTML

Thanks