Need to compare value with custom field of pick list datatype in SFDC

2.2k views Asked by At

I am new to SFDC, I have a program where I'm passing the values and I need to compare these values with a custom object field where it is present or not.

Here is my code,

public class CheckUtility {

    public static ID determineFeature(ID defaultPersonaID, String Email, String Industry, String Title, Decimal Revenue, Integer EmployeeCount) {

        ID fetrID = defaultFeatureID;
        String emailDomain = Email.split('@').get(1);           
        Feature__c[] features = new Feature__c[]{};
        features = [Select id, Industries__c, Title_Tags__c, Email_Domains__c, Company_Revenue_From__c, Company_Revenue_To__c, Employee_Count_From__c, Employee_Count_To__c FROM Feature__c ORDER BY lastModifiedDate DESC];
        Integer industriesFound = 0;
        for (feature__c p: features) {
     // checking if there is a matching feature based on email    
        System.debug('Email Domains = ' + p.email_domains__c);        
             if (p.Email_Domains__c != null &&     
        p.Email_Domains__c.contains(emailDomain)) {
                 fetrID = p.ID;
                break;
             }

             if(p.Industries__c != null){ 
  //I am stuck compare the industry is present or not in the p.Industries__c (picklistdatatype)

               System.debug('Industries' + p.Industries__c);        
                 fetrID = p.ID;
                break;
             }
        }                

        return fetrID;      
    }      
}

No. I have Feature__c is a custom object. Feature__c.Industries__c custom field can have one value or multiple values.

ex:  Feature__c (object)

id                | Industries__c
a010b00000eERj4   | technology
a010b00000eEYu4   | finance, biotechology
a010b00000eHJj8   | chemical, healthcare

I want to check whether Industry (which is coming via value passed in determineFeature  ) is equal with how many Industries__c in Feature__c and send their fetrID's in response.

2

There are 2 answers

0
Maria On

What I understand I implement Below. If any query or misunderstand the question pls let me know.

With the value you need to compare in custom object.

public class custom_ctrl{

public Feature__c fetur {get;set;}
public String comparvalue {get;set;}

public custom_ctrl()
{
  fetur =new Feature__c ();

  fetur=[select Name,Email from feature__c where Name=:comparvalue ]

  if(comparvalue == fetur.Name)      
 {
     //action
 }
 else
 {
     //else action
 }

}
0
Jo_gurt On

Multiselect picklist in the backend is just a text field with semicolon-separated values, so you can do something like:

Set<String> industries = new Set<String>()
industries.addAll(String.split(p.Industries__c, ';')); 
if (industries.contains(Industry)) { ... }

BTW, this is redundant:

Feature__c[] features = new Feature__c[]{};
features = [Select id, (...)

As [SELECT] always returns list, even if it's empty.