需要将值与SFDC中的选择列表数据类型的自定义字段进行比较

时间:2018-09-17 14:45:37

标签: salesforce apex-code apex salesforce-service-cloud sfdc

我是SFDC的新手,我有一个程序在其中传递值,我需要将这些值与是否存在自定义对象字段进行比较。

这是我的代码,

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;      
    }      
}

不。 我有Feature__c是一个自定义对象。 Feature__c.Industries__c自定义字段可以具有一个值或多个值。

例如:Feature__c(对象)

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

我想检查行业(通过确定属性传递的值来确定)是否等于功能__c中的多少个行业__c,并发送它们的fetrID作为响应。

2 个答案:

答案 0 :(得分:0)

后端的多选选择列表只是一个用分号分隔的值的文本字段,因此您可以执行以下操作:

b

顺便说一句,这是多余的:

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

由于[SELECT]始终返回列表,即使它为空。

答案 1 :(得分:0)

我了解的是我在下面实现的。如果有任何疑问或误解,请告诉我。

您需要在自定义对象中进行比较的值。

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
 }

}