function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC Developer1SFDC Developer1 

Apex describe picklist values

I have one custom object abc__c which has one text field number__c and i have another object temp__c which have one picklist field.

I want to check if the value of number__c field from first object present in temp__c picklist field of second object.

I am using getDescribe() but I am not able to do the comparison.
If the value is present, I want to perform few actions and if not present then I want to perform another action. Kindly help as i am new to the development.
Suraj Tripathi 47Suraj Tripathi 47
Hii there,
abc__c obj = new abc__c (number__c ='Test');
temp__c  tmp = new temp__c ();
//tmp.Country= 'Testing';//Picklist Value
temp__c  .fields.Country.getDescribe().getpicklistvalues();
The above will return you all the possible picklist values. You can loop through the values or use a map to "search" it. 

This functionality is called dynamic Apex!
CharuDuttCharuDutt
Hii Sfdc Developer
Try Below Code
String objectName = 'Account';
String fieldName ='Rating';

Schema.SObjectType s = Schema.getGlobalDescribe().get(objectName) ;
Schema.DescribeSObjectResult r = s.getDescribe() ;
Map<String,Schema.SObjectField> fields = r.fields.getMap() ;
Schema.DescribeFieldResult fieldResult = fields.get(fieldName).getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry pickListVal : ple){
    System.debug(pickListVal.getLabel() +' '+pickListVal.getValue());
}
Please Mark It As Best Answer If It Helps
Thank You!
SFDC Developer1SFDC Developer1
thanks for the comment.
I should i compare value of my text fields with pickListVal?