+ Start a Discussion
abc_defabc_def 

how to compare a value in one picklist with other picklist in apex classes???

hi,

 can anybody help me in this topic.

DonSpilkyDonSpilky

The value in a picklist is simply the value of that datatype.  If you have a picklist of type string, then simply compare that string value to another.

abc_defabc_def

can you please help me  through a code written in apex class

BomanBoman

Simply comparing the currently selected values in two picklists is very straightforward:

 

if (<yourObject__c>.pickListOneFieldName__c != <yourObject__c>.pickListTwoFieldName__c) ...

 

Now, if you are asking how to compare *all* possible values that can be held by the two picklists, then you need to access the metadata API:

 

Schema.DescribeFieldResult fieldResult1 = <yourObject__c>.pickListOneFieldName__c.getDescribe();

List<Schema.PicklistEntry> ple1 = fieldResult1.getPicklistValues();


Schema.DescribeFieldResult fieldResult2 = <yourObject__c>.pickListTwoFieldName__c.getDescribe();

List<Schema.PicklistEntry> ple2 = fieldResult2.getPicklistValues();


// Loop over the Lists and compare as desired

        for (Schema.PicklistEntry f : ple1) {

             for (Schema.PicklistEntry f : ple2) {

                 <<compare>>

             }

         }