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
mohan s 37mohan s 37 

Method does not exist or incorrect signature: [Set<String>].containsIgnoreCase(String)

Hi Friends,

I am getting following error in my trigger while ignoring the casesensitive. can any one help me what mistake did i made in the following trigger.
My requirement is to autopopulate Region__c custom field in Account when i give Account billing country. For this requirement I have created custom setting called country_Names__c with country_Region as custom field. without containsIgnoreCase it is working fine but when i try to enter Billingcountry in lowercase the Region__c field is not autopopulated for this i want to ignore the caseinsensitive.
error:"Method does not exist or incorrect signature: [Set<String>].containsIgnoreCase(String)"
trigger:
trigger ReportsAccount on Account (before insert, before update) {
    Map<string,Country_Names__c> countries=Country_Names__c.getAll();//get all the countries
     set<string> countrynames= new set<string>();
    countrynames.addAll(countries.keySet()); // add map country keys to set
    if(trigger.isInsert){
    for(Account a:trigger.new){
        if(countrynames.containsIgnoreCase(a.BillingCountry)){  //error line without ignore case it is working fine
            a.Region__c=countries.get(a.BillingCountry).Country_Region__c;
        }
    } // loop ends
    }
    if(trigger.isUpdate){
        for(Account updateacc: trigger.new){
            if(countrynames.contains(updateacc.BillingCountry)){
              updateacc.Region__c=countries.get(updateacc.BillingCountry).Country_Region__c;  
            }  
        }// loop ends
    }
}
Best Answer chosen by mohan s 37
Amit Chaudhary 8Amit Chaudhary 8
Hi ,

Issue is coming because you are using String method with Set. you can try any of below solution

Please update your code like below . Same code will work with insert and update case.
trigger ReportsAccount on Account (before insert, before update) 
{
    Map<string,Country_Names__c> countries = Country_Names__c.getAll();//get all the countries

	for(Account a:trigger.new)
	{
		for(String s : countries.keySet())
		{ 
			if(s.containsIgnoreCase(a.BillingCountry))
			{
				a.Region__c=countries.get(s).Country_Region__c;
			}
		}
	}
}

Let us know if this will help you


 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi mohan
try this code
trigger ReportsAccount on Account (before insert, before update) {
    Map<string,Country_Names__c> countries = Country_Names__c.getAll();//get all the countries
    system.debug('countries' + countries);
     set<string> countrynames= new set<string>();
    countrynames.addAll(countries.keySet()); // add map country keys to set
    system.debug('countrynames' + countrynames);
    if(trigger.isInsert){
    for(Account a:trigger.new){
       for(String s : countrynames){ 
        if(s.containsIgnoreCase(a.BillingCountry)){  //error line without ignore case it is working fine
            a.Region__c=countries.get(a.BillingCountry).Country_Region__c;
        }
        }
    } // loop ends
    }
    if(trigger.isUpdate){
        for(Account updateacc: trigger.new){
                if(countrynames.contains(updateacc.BillingCountry)){
              updateacc.Region__c=countries.get(updateacc.BillingCountry).Country_Region__c;  
            }  
        }// loop ends
    }
}
let me infotm if it helps you
thanks :)

 
Amit Chaudhary 8Amit Chaudhary 8
Hi ,

Issue is coming because you are using String method with Set. you can try any of below solution

Please update your code like below . Same code will work with insert and update case.
trigger ReportsAccount on Account (before insert, before update) 
{
    Map<string,Country_Names__c> countries = Country_Names__c.getAll();//get all the countries

	for(Account a:trigger.new)
	{
		for(String s : countries.keySet())
		{ 
			if(s.containsIgnoreCase(a.BillingCountry))
			{
				a.Region__c=countries.get(s).Country_Region__c;
			}
		}
	}
}

Let us know if this will help you


 
This was selected as the best answer
mohan s 37mohan s 37
Thank you Piyush you always helped me a lot I heartfully thank you for your encouragable support.
mohan s 37mohan s 37
Thank you Amit chaudhary your effort helped me a lot I used to learn something from your. Your help is really appreciated.
sfdcMonkey.comsfdcMonkey.com
Happy to help ;)