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
SabrentSabrent 

Method does not exist or incorrect signature: [SET<String>].contains

can someone point out what i am doing wrong, or what is the correct way to find if the picklist field contains any of the mentioned values.


Save error: Method does not exist or incorrect signature: [SET<String>].contains(String, String, String, String, String, String, String)

 

 

Schema.DescribeFieldResult F = Object__c.Picklist_Field__c.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();

set<string> s1 = new set<string>();
for ( Schema.PicklistEntry p1: p){

s1.add(p1.getValue());

system.debug(s1);
}
if (Field1__c == 0) {


if (s1.contains('Support Calls- A','IT Help Desk-L1','IT Help Desk - L2','Support Calls- B','Support Calls- C','Support Calls- D')){    // this is where the error is

Total = a.otherField__c ;

}

 

Best Answer chosen by Admin (Salesforce Developers) 
Eva DeLoriolEva DeLoriol

Hi rov,

 

I think it probably has something to do with the long string you're checking on?  Try it with one of the values first and see if that works.  You may have to do a few if statements to get through all of the values you want to check for. 

 

if (val.contains('Support Calls- A')){
//do something
}

 I think the contains method can't accept all those values at once.

 

- Eva

All Answers

Eva DeLoriolEva DeLoriol

Hi - I don't think you need the Set here. 

 

You could try something like:

 

Schema.DescribeFieldResult F = Object__c.Picklist_Field__c.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();

for(Schema.PicklistEntry sl : p){
    String val =  sl.getValue();
    if (val.contains('Support Calls- A','IT Help Desk-L1','IT Help Desk - L2','Support Calls- B','Support Calls- C','Support Calls- D')){ 

Total = a.otherField__c ;
break;
}

 You've got your picklist values, you just need to loop through them to find the value. 

 

I hope this helps you out.

Eva

Jia HuJia Hu
set<string> myString = new Set<String>{'Support Calls- A','IT Help Desk-L1','IT Help Desk - L2','Support Calls- B','Support Calls- C','Support Calls- D'};

s1.containsall(myString) ;
SabrentSabrent

Thanks @ Eva and @Jia

 

I will try your suggestions and let you know how i go

SabrentSabrent

Eva I tried as you suggested getting the same error

 

Save error: Method does not exist or incorrect signature: [String].contains(String, String, String, String, String, String, String, String, String, String)   

Schema.DescribeFieldResult F = Forecast__c.Type__c.getDescribe();

List<Schema.PicklistEntry> P = F.getPicklistValues();
        	
    	for ( Schema.PicklistEntry s1: p){
        	
        			
        	String val = s1.getValue();


if (val.contains('Support Calls- A','IT Help Desk-L1','IT Help Desk - L2','Support Calls- B','Support Calls- C','Support Calls- D','IT Help Desk-L3','IT Help Desk-LA1','IT Help Desk-LA2','IT Help Desk-LA3')){

Total = a.otherField__c ;
break;
}

 

 

Eva DeLoriolEva DeLoriol

Hi rov,

 

I think it probably has something to do with the long string you're checking on?  Try it with one of the values first and see if that works.  You may have to do a few if statements to get through all of the values you want to check for. 

 

if (val.contains('Support Calls- A')){
//do something
}

 I think the contains method can't accept all those values at once.

 

- Eva

This was selected as the best answer
SabrentSabrent

Thanks. you are right, takes only one string value.  Appreciate your help and time.

 

I guess, I will have to do,

 

if (val.contains('Support Calls- A') || val.contains('Support Calls- B'))